Skip to content

Commit

Permalink
Merge pull request #2 from ADPRO-C11/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
sdikyarts authored May 8, 2024
2 parents 436819a + 73efc84 commit 77f0c3f
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 103 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ val webdrivermanagerVersion = "5.6.3"
val junitJupiterVersion = "5.9.1"

dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-web")
compileOnly("org.projectlombok:lombok")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("org.postgresql:postgresql")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-test")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package snackscription.subscriptionadmin.enums;

import lombok.Getter;

@Getter
public enum SubscriptionStatus {
PENDING("PENDING"),
REJECTED("REJECTED"),
SUBSCRIBED("SUBSCRIBED");

private final String value;

private SubscriptionStatus(String value) {
this.value = value;
}

public static boolean contains(String param) {
for (SubscriptionStatus subscriptionStatus : SubscriptionStatus.values()) {
if (subscriptionStatus.name().equals(param)) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package snackscription.subscriptionadmin.factory;

import snackscription.subscriptionadmin.repository.AdminRepository;

public class AdminRepositoryFactory implements Factory<AdminRepository> {
@Override
public AdminRepository create() {
return new AdminRepository();
}

public AdminRepository create(String subscriberName, String subscriberId, String uniqueCode, String subscriptionBoxId, String subscriptionStatus) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package snackscription.subscriptionadmin.factory;

import snackscription.subscriptionadmin.model.AdminSubscription;

public class AdminSubscriptionFactory implements Factory<AdminSubscription> {
@Override
public AdminSubscription create() {
return new AdminSubscription();
}

public AdminSubscription create(String subscriberName, String subscriberId, String uniqueCode, String subscriptionBoxId, String subscriptionStatus) {
return new AdminSubscription(subscriberName, subscriberId, uniqueCode, subscriptionBoxId, subscriptionStatus);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package snackscription.subscriptionadmin.factory;

public interface Factory <F> {
F create();
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
package snackscription.subscriptionadmin.model;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import snackscription.subscriptionadmin.enums.SubscriptionStatus;

import java.util.UUID;

@Getter @Setter
public class AdminSubscription {
private String subscriberName;
private int subscriberId;
private String subscriptionUniqueCode;
private String subscriptionType;
private String subscribtionStatus;
String subscriberName;
String subscriberId;
String uniqueCode;
String subscriptionId;
String subscriptionBoxId;
String subscriptionStatus;

public AdminSubscription() {
this.subscriptionId = UUID.randomUUID().toString();
}

public AdminSubscription(String subscriberName, String subscriberId, String uniqueCode, String subscriptionBoxId, String subscriptionStatus) {
this.subscriptionId = UUID.randomUUID().toString();

this.subscriberName = subscriberName;
this.subscriberId = subscriberId;

if (!uniqueCode.startsWith("MTH-") && !uniqueCode.startsWith("QTR-") && !uniqueCode.startsWith("SAA-")) {
throw new IllegalArgumentException("Invalid unique code");
}

this.uniqueCode = uniqueCode;
this.subscriptionBoxId = subscriptionBoxId;
this.getSubscriptionStatus();
this.setSubscriptionStatus(subscriptionStatus);
}

public void setSubscriptionStatus(String subscriptionStatus) {
if (SubscriptionStatus.contains(subscriptionStatus)) {
this.subscriptionStatus = subscriptionStatus;
} else {
throw new IllegalArgumentException("Invalid subscription status");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package snackscription.subscriptionadmin.factory;

import org.junit.jupiter.api.Test;
import snackscription.subscriptionadmin.repository.AdminRepository;

import static org.junit.jupiter.api.Assertions.*;

public class AdminRepositoryFactoryTest {
@Test
void testCreateAdminRepository() {
AdminRepositoryFactory adminRepositoryFactory = new AdminRepositoryFactory();
AdminRepository adminRepository = adminRepositoryFactory.create();

assertNotNull(adminRepository);
assertInstanceOf(AdminRepository.class, adminRepository);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package snackscription.subscriptionadmin.factory;

import org.junit.jupiter.api.Test;
import snackscription.subscriptionadmin.enums.SubscriptionStatus;
import snackscription.subscriptionadmin.model.AdminSubscription;

import static org.junit.jupiter.api.Assertions.*;

public class AdminSubscriptionFactoryTest {
@Test
void testCreateAdminSubscription() {
AdminSubscriptionFactory adminSubscriptionFactory = new AdminSubscriptionFactory();
AdminSubscription adminSubscription = adminSubscriptionFactory.create();

assertNotNull(adminSubscription);
}

@Test
void testCreateAdminSubscriptionComplete() {
AdminSubscriptionFactory adminSubscriptionFactory = new AdminSubscriptionFactory();

AdminSubscription adminSubscription = adminSubscriptionFactory.create(
"Hwang Hyunjin",
"12345678910",
"MTH-12345678910",
"12345678910",
SubscriptionStatus.PENDING.getValue()
);

assertNotNull(adminSubscription.getSubscriptionId());
assertEquals("Hwang Hyunjin", adminSubscription.getSubscriberName());
assertEquals("12345678910", adminSubscription.getSubscriberId());
assertEquals("MTH-12345678910", adminSubscription.getUniqueCode());
assertEquals("12345678910", adminSubscription.getSubscriptionBoxId());
assertEquals(SubscriptionStatus.PENDING.getValue(), adminSubscription.getSubscriptionStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import snackscription.subscriptionadmin.enums.SubscriptionStatus;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -11,35 +12,56 @@ class AdminSubscriptionTest {
@BeforeEach
void setUp() {
this.adminSubscription = new AdminSubscription();
this.adminSubscription.setSubscriberId(1);
this.adminSubscription.setSubscriberName("Hwang Hyunjin");
this.adminSubscription.setSubscriptionType("Monthly");
this.adminSubscription.setSubscriptionUniqueCode("123456");
this.adminSubscription.setSubscribtionStatus("Pending");
this.adminSubscription.setSubscriberId("12345678910");
this.adminSubscription.setSubscriptionId("12345678910");
this.adminSubscription.setUniqueCode("MTH-12345678910");
this.adminSubscription.setSubscriptionBoxId("12345678910");

this.adminSubscription.setSubscriptionStatus(SubscriptionStatus.PENDING.getValue());
}

@Test
void testGetSubscriberName() {
assertEquals("Hwang Hyunjin", this.adminSubscription.getSubscriberName());
}

@Test
void testGetSubscriberId() {
assertEquals(1, this.adminSubscription.getSubscriberId());
assertEquals("12345678910", this.adminSubscription.getSubscriberId());
}

@Test
void testGetSubscriberName() {
assertEquals("Hwang Hyunjin", this.adminSubscription.getSubscriberName());
void testGetSubscriptionId() {
assertEquals("12345678910", this.adminSubscription.getSubscriptionId());
}

@Test
void testGetSubscriptionType() {
assertEquals("Monthly", this.adminSubscription.getSubscriptionType());
void testGetUniqueCode() {
assertEquals("MTH-12345678910", this.adminSubscription.getUniqueCode());
}

@Test
void testGetSubscriptionUniqueCode() {
assertEquals("123456", this.adminSubscription.getSubscriptionUniqueCode());
void testGetSubscriptionBoxId() {
assertEquals("12345678910", this.adminSubscription.getSubscriptionBoxId());
}

@Test
void testGetSubscribtionStatus() {
assertEquals("Pending", this.adminSubscription.getSubscribtionStatus());
void testGetSubscriptionStatus() {
assertEquals(SubscriptionStatus.PENDING.getValue(), adminSubscription.getSubscriptionStatus());
}

@Test
void testSetSubscriptionStatus() {
this.adminSubscription.setSubscriptionStatus(SubscriptionStatus.SUBSCRIBED.getValue());
assertEquals(SubscriptionStatus.SUBSCRIBED.getValue(), this.adminSubscription.getSubscriptionStatus());
}

@Test
void testSetInvalidSubscriptionStatus() {
assertThrows(IllegalArgumentException.class, () -> {
this.adminSubscription.setSubscriptionStatus("INVALID");
});
}

}

This file was deleted.

0 comments on commit 77f0c3f

Please sign in to comment.