forked from pierront/mylibrary-template
✅ réussite des tests de base, c'était long
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription;
|
||||||
|
|
||||||
|
public record PaymentMethodInfo(String paymentType, Object details) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription;
|
||||||
|
|
||||||
|
public enum PaymentType {
|
||||||
|
CB,
|
||||||
|
PAYPAL;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription;
|
||||||
|
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity.PaymentMethod;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Getter
|
||||||
|
public class SubscriptionDTO {
|
||||||
|
|
||||||
|
private UUID subscriptionId;
|
||||||
|
private UUID customerId;
|
||||||
|
private Integer subscriptionDurationDesired;
|
||||||
|
private PaymentMethod paymentMethod;
|
||||||
|
private LocalDate desiredStartDate;
|
||||||
|
private LocalDate startDate;
|
||||||
|
private LocalDate endDate;
|
||||||
|
private double monthlyAmount;
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription;
|
||||||
|
|
||||||
|
public enum SubscriptionDurationDesired {
|
||||||
|
THREE(3),
|
||||||
|
SIX(6),
|
||||||
|
TWELVE(12);
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
SubscriptionDurationDesired(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
public record SubscriptionInfo(Integer subscriptionDurationDesired, LocalDate desiredStartDate) {
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.converter;
|
||||||
|
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.customer.CustomerDTO;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.PaymentMethodInfo;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.SubscriptionDTO;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.SubscriptionInfo;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity.PaymentMethod;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity.Subscription;
|
||||||
|
|
||||||
|
public class SubscriptionConverter {
|
||||||
|
|
||||||
|
private SubscriptionConverter(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Subscription toDomain(SubscriptionInfo newSubscription, PaymentMethodInfo newPaymentMethod) {
|
||||||
|
PaymentMethod paymentMethod = PaymentMethod.builder()
|
||||||
|
.paymentType(newPaymentMethod.paymentType())
|
||||||
|
.details(newPaymentMethod.details())
|
||||||
|
.build();
|
||||||
|
return Subscription.builder()
|
||||||
|
.subscriptionDurationDesired(newSubscription.subscriptionDurationDesired())
|
||||||
|
.paymentMethod(paymentMethod)
|
||||||
|
.desiredStartDate(newSubscription.desiredStartDate())
|
||||||
|
.startDate(newSubscription.desiredStartDate())
|
||||||
|
.endDate(newSubscription.desiredStartDate().plusMonths(newSubscription.subscriptionDurationDesired()))
|
||||||
|
.monthlyAmount(0)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SubscriptionDTO toDTO(Subscription subscription) {
|
||||||
|
return SubscriptionDTO.builder()
|
||||||
|
.subscriptionId(subscription.getSubscriptionId())
|
||||||
|
.customerId(subscription.getCustomerId())
|
||||||
|
.subscriptionDurationDesired(subscription.getSubscriptionDurationDesired())
|
||||||
|
.paymentMethod(subscription.getPaymentMethod())
|
||||||
|
.desiredStartDate(subscription.getDesiredStartDate())
|
||||||
|
.startDate(subscription.getStartDate())
|
||||||
|
.endDate(subscription.getEndDate())
|
||||||
|
.monthlyAmount(subscription.getMonthlyAmount())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Getter
|
||||||
|
public class PaymentMethod {
|
||||||
|
|
||||||
|
private String paymentType;
|
||||||
|
private Object details;
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Getter
|
||||||
|
public class Subscription {
|
||||||
|
|
||||||
|
private UUID subscriptionId;
|
||||||
|
private UUID customerId;
|
||||||
|
private Integer subscriptionDurationDesired;
|
||||||
|
private PaymentMethod paymentMethod;
|
||||||
|
private LocalDate desiredStartDate;
|
||||||
|
private LocalDate startDate;
|
||||||
|
private LocalDate endDate;
|
||||||
|
private double monthlyAmount;
|
||||||
|
|
||||||
|
public void setRandomSubscriptionUUID() {
|
||||||
|
|
||||||
|
this.subscriptionId = UUID.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRandomCustomerUUID() {
|
||||||
|
|
||||||
|
this.customerId = UUID.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartDate(){
|
||||||
|
this.startDate = this.desiredStartDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndDate(){
|
||||||
|
this.endDate = this.desiredStartDate.plusMonths(this.subscriptionDurationDesired);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateSubscription(){
|
||||||
|
setStartDate();
|
||||||
|
setEndDate();
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-2
@@ -1,5 +1,8 @@
|
|||||||
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.converter;
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.converter;
|
||||||
|
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.*;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity.PaymentMethod;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity.Subscription;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -73,7 +76,7 @@ public class SubscriptionConverterTest {
|
|||||||
assertEquals(subscription.getSubscriptionDurationDesired(), result.getSubscriptionDurationDesired());
|
assertEquals(subscription.getSubscriptionDurationDesired(), result.getSubscriptionDurationDesired());
|
||||||
assertEquals(subscription.getPaymentMethod().getPaymentType(), result.getPaymentMethod().getPaymentType());
|
assertEquals(subscription.getPaymentMethod().getPaymentType(), result.getPaymentMethod().getPaymentType());
|
||||||
assertEquals(subscription.getPaymentMethod().getDetails(), result.getPaymentMethod().getDetails());
|
assertEquals(subscription.getPaymentMethod().getDetails(), result.getPaymentMethod().getDetails());
|
||||||
assertEquals(subscription.desiredStartDate(), result.getStartDateDesired());
|
assertEquals(subscription.getDesiredStartDate(), result.getDesiredStartDate());
|
||||||
assertEquals(subscription.getStartDate(), result.getStartDate());
|
assertEquals(subscription.getStartDate(), result.getStartDate());
|
||||||
assertEquals(subscription.getEndDate(), result.getEndDate());
|
assertEquals(subscription.getEndDate(), result.getEndDate());
|
||||||
assertEquals(12.03, result.getMonthlyAmount());
|
assertEquals(12.03, result.getMonthlyAmount());
|
||||||
@@ -100,7 +103,7 @@ public class SubscriptionConverterTest {
|
|||||||
.monthlyAmount(12.03)
|
.monthlyAmount(12.03)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
SubscriptionDTO result = SubscriptionConverter.toDTO(customer);
|
SubscriptionDTO result = SubscriptionConverter.toDTO(subscription);
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertNull(result.getPaymentMethod().getDetails());
|
assertNull(result.getPaymentMethod().getDetails());
|
||||||
|
|||||||
+7
-6
@@ -1,5 +1,6 @@
|
|||||||
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity;
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity;
|
||||||
|
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.PaymentType;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -8,8 +9,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
public class PaymentMethodTest {
|
public class PaymentMethodTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Builder should create a valid Subscription instance")
|
@DisplayName("Builder should create a valid PaymentMethod instance")
|
||||||
void testSubscriptionBuilder() {
|
void testPaymentMethodBuilder() {
|
||||||
String paymentType = PaymentType.CB.name();
|
String paymentType = PaymentType.CB.name();
|
||||||
Object details = new Object();
|
Object details = new Object();
|
||||||
details = "Maxime Lebreton";
|
details = "Maxime Lebreton";
|
||||||
@@ -24,8 +25,8 @@ public class PaymentMethodTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Builder should create a valid Subscription instance with details as an Integer")
|
@DisplayName("Builder should create a valid PaymentMethod instance with details as an Integer")
|
||||||
void testSubscriptionBuilder() {
|
void testPaymentMethodDetailsInteger() {
|
||||||
String paymentType = PaymentType.CB.name();
|
String paymentType = PaymentType.CB.name();
|
||||||
Object details = new Object();
|
Object details = new Object();
|
||||||
details = 10;
|
details = 10;
|
||||||
@@ -40,8 +41,8 @@ public class PaymentMethodTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Builder should create a valid Subscription instance with details as an boolean")
|
@DisplayName("Builder should create a valid PaymentMethod instance with details as an boolean")
|
||||||
void testSubscriptionBuilder() {
|
void testPaymentMethodDetailsBoolean() {
|
||||||
String paymentType = PaymentType.CB.name();
|
String paymentType = PaymentType.CB.name();
|
||||||
Object details = new Object();
|
Object details = new Object();
|
||||||
details = true;
|
details = true;
|
||||||
|
|||||||
+9
-7
@@ -1,5 +1,7 @@
|
|||||||
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity;
|
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.entity;
|
||||||
|
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.PaymentType;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.subscription.SubscriptionDurationDesired;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ public class SubscriptionTest {
|
|||||||
Subscription subscription = Subscription.builder().build();
|
Subscription subscription = Subscription.builder().build();
|
||||||
UUID originalId = subscription.getCustomerId();
|
UUID originalId = subscription.getCustomerId();
|
||||||
|
|
||||||
Subscription.setRandomCustomerUUID();
|
subscription.setRandomCustomerUUID();
|
||||||
|
|
||||||
assertNotNull(subscription.getCustomerId());
|
assertNotNull(subscription.getCustomerId());
|
||||||
assertNotEquals(originalId, subscription.getCustomerId());
|
assertNotEquals(originalId, subscription.getCustomerId());
|
||||||
@@ -77,13 +79,13 @@ public class SubscriptionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("setStartDate should instantiate StartDate as the same value as the variable desiredStartDate")
|
@DisplayName("setStartDate should instantiate StartDate as the same value as the variable desiredStartDate")
|
||||||
void testSetRandomCustomerUUID() {
|
void testSetStartDate() {
|
||||||
LocalDate desiredStartDate = LocalDate.of(2026, 3, 24);
|
LocalDate desiredStartDate = LocalDate.of(2026, 3, 24);
|
||||||
Subscription subscription = Subscription.builder()
|
Subscription subscription = Subscription.builder()
|
||||||
.desiredStartDate(desiredStartDate)
|
.desiredStartDate(desiredStartDate)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Subscription.setStartDate();
|
subscription.setStartDate();
|
||||||
|
|
||||||
assertNotNull(subscription.getStartDate());
|
assertNotNull(subscription.getStartDate());
|
||||||
assertEquals(desiredStartDate, subscription.getStartDate());
|
assertEquals(desiredStartDate, subscription.getStartDate());
|
||||||
@@ -91,7 +93,7 @@ public class SubscriptionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("setEndDate should instantiate EndDate as the same value as the variable desiredStartDate + subscriptionDurationDesired")
|
@DisplayName("setEndDate should instantiate EndDate as the same value as the variable desiredStartDate + subscriptionDurationDesired")
|
||||||
void testSetRandomCustomerUUID() {
|
void testSetEndDate() {
|
||||||
LocalDate desiredStartDate = LocalDate.of(2026, 3, 24);
|
LocalDate desiredStartDate = LocalDate.of(2026, 3, 24);
|
||||||
LocalDate estimateEndDate = LocalDate.of(2026, 6, 24);
|
LocalDate estimateEndDate = LocalDate.of(2026, 6, 24);
|
||||||
Subscription subscription = Subscription.builder()
|
Subscription subscription = Subscription.builder()
|
||||||
@@ -99,7 +101,7 @@ public class SubscriptionTest {
|
|||||||
.desiredStartDate(desiredStartDate)
|
.desiredStartDate(desiredStartDate)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Subscription.setEndDate();
|
subscription.setEndDate();
|
||||||
|
|
||||||
assertNotNull(subscription.getEndDate());
|
assertNotNull(subscription.getEndDate());
|
||||||
assertEquals(estimateEndDate, subscription.getEndDate());
|
assertEquals(estimateEndDate, subscription.getEndDate());
|
||||||
@@ -107,7 +109,7 @@ public class SubscriptionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("setDateSubscription should instantiate StartDate and EndDate ")
|
@DisplayName("setDateSubscription should instantiate StartDate and EndDate ")
|
||||||
void testSetRandomCustomerUUID() {
|
void testSetDateSubscription() {
|
||||||
LocalDate desiredStartDate = LocalDate.of(2026, 3, 24);
|
LocalDate desiredStartDate = LocalDate.of(2026, 3, 24);
|
||||||
LocalDate estimateEndDate = LocalDate.of(2026, 6, 24);
|
LocalDate estimateEndDate = LocalDate.of(2026, 6, 24);
|
||||||
Subscription subscription = Subscription.builder()
|
Subscription subscription = Subscription.builder()
|
||||||
@@ -115,7 +117,7 @@ public class SubscriptionTest {
|
|||||||
.desiredStartDate(desiredStartDate)
|
.desiredStartDate(desiredStartDate)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Subscription.setDateSubscription();
|
subscription.setDateSubscription();
|
||||||
|
|
||||||
assertNotNull(subscription.getEndDate());
|
assertNotNull(subscription.getEndDate());
|
||||||
assertEquals(estimateEndDate, subscription.getEndDate());
|
assertEquals(estimateEndDate, subscription.getEndDate());
|
||||||
|
|||||||
Reference in New Issue
Block a user