From f8dd1a354b301d1777e469ca90fea8783c07e7c5 Mon Sep 17 00:00:00 2001 From: Rhaja <40422415+DRHAJA@users.noreply.github.com> Date: Sat, 19 Apr 2025 21:21:10 +0800 Subject: [PATCH 1/4] Modify the StringValueObject base class --- .../tv/codely/shared/domain/StringValueObject.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/shared/main/tv/codely/shared/domain/StringValueObject.java b/src/shared/main/tv/codely/shared/domain/StringValueObject.java index 45525e50..2b13b207 100644 --- a/src/shared/main/tv/codely/shared/domain/StringValueObject.java +++ b/src/shared/main/tv/codely/shared/domain/StringValueObject.java @@ -3,9 +3,12 @@ import java.util.Objects; public abstract class StringValueObject { - private String value; + private final String value; public StringValueObject(String value) { + if (value == null || value.trim().isEmpty()) { + throw new IllegalArgumentException("Value cannot be null or empty"); + } this.value = value; } @@ -20,12 +23,8 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof StringValueObject)) { - return false; - } + if (this == o) return true; + if (!(o instanceof StringValueObject)) return false; StringValueObject that = (StringValueObject) o; return Objects.equals(value, that.value); } From 85a636d4bb5cf9b533eebaa5d66f2ca86cb2979d Mon Sep 17 00:00:00 2001 From: yennnn03 Date: Wed, 23 Apr 2025 00:33:10 +0800 Subject: [PATCH 2/4] Update BackofficeContextInfrastructureTestCase.java --- .../backoffice/BackofficeContextInfrastructureTestCase.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java b/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java index efbad4e7..1df5a005 100644 --- a/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java +++ b/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java @@ -8,6 +8,7 @@ import tv.codely.shared.infrastructure.InfrastructureTestCase; import java.io.IOException; +import java.util.logging.Logger; @ContextConfiguration(classes = BackofficeFrontendApplication.class) @SpringBootTest @@ -15,7 +16,9 @@ public abstract class BackofficeContextInfrastructureTestCase extends Infrastruc @Autowired private ElasticsearchEnvironmentArranger elasticsearchArranger; + private static final Logger logger = Logger.getLogger(BackofficeContextInfrastructureTestCase.class.getName()); protected void clearElasticsearch() throws IOException { + logger.info("Clearing Elasticsearch indices: backoffice, backoffice_courses"); elasticsearchArranger.arrange("backoffice", "backoffice_courses"); } } From 41af440673b8cb03f6963a7c89f8a479d3869e5e Mon Sep 17 00:00:00 2001 From: yennnn03 Date: Wed, 23 Apr 2025 01:18:42 +0800 Subject: [PATCH 3/4] Change code BackofficeContextInfrastructureTestCase.java --- .../backoffice/BackofficeContextInfrastructureTestCase.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java b/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java index 1df5a005..ff1aa571 100644 --- a/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java +++ b/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java @@ -22,3 +22,4 @@ protected void clearElasticsearch() throws IOException { elasticsearchArranger.arrange("backoffice", "backoffice_courses"); } } +//Add the logging function From 51b9af0ae46a5b9294b89130781ad7ca2ab119bc Mon Sep 17 00:00:00 2001 From: Rhaja <40422415+DRHAJA@users.noreply.github.com> Date: Wed, 23 Apr 2025 09:24:58 +0800 Subject: [PATCH 4/4] simplify and deduplicate logic in ApplicationTestCase --- .../tv/codely/apps/ApplicationTestCase.java | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/apps/test/tv/codely/apps/ApplicationTestCase.java b/apps/test/tv/codely/apps/ApplicationTestCase.java index d3568189..e87ef6db 100644 --- a/apps/test/tv/codely/apps/ApplicationTestCase.java +++ b/apps/test/tv/codely/apps/ApplicationTestCase.java @@ -6,7 +6,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import java.util.Arrays; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -23,45 +23,45 @@ @AutoConfigureMockMvc public abstract class ApplicationTestCase { - @Autowired - private MockMvc mockMvc; + @Autowired + private MockMvc mockMvc; - @Autowired - private EventBus eventBus; + @Autowired + private EventBus eventBus; - protected void assertResponse(String endpoint, Integer expectedStatusCode, String expectedResponse) throws Exception { - ResultMatcher response = expectedResponse.isEmpty() ? content().string("") : content().json(expectedResponse); + private ResultMatcher expectedContent(String response) { + return response.isEmpty() ? content().string("") : content().json(response); + } - mockMvc.perform(get(endpoint)).andExpect(status().is(expectedStatusCode)).andExpect(response); - } + protected void assertResponse(String endpoint, Integer expectedStatusCode, String expectedResponse) throws Exception { + mockMvc.perform(get(endpoint)) + .andExpect(status().is(expectedStatusCode)) + .andExpect(expectedContent(expectedResponse)); + } - protected void assertResponse( - String endpoint, - Integer expectedStatusCode, - String expectedResponse, - HttpHeaders headers - ) throws Exception { - ResultMatcher response = expectedResponse.isEmpty() ? content().string("") : content().json(expectedResponse); + protected void assertResponse(String endpoint, Integer expectedStatusCode, String expectedResponse, HttpHeaders headers) + throws Exception { + mockMvc.perform(get(endpoint).headers(headers)) + .andExpect(status().is(expectedStatusCode)) + .andExpect(expectedContent(expectedResponse)); + } - mockMvc.perform(get(endpoint).headers(headers)).andExpect(status().is(expectedStatusCode)).andExpect(response); - } + protected void assertRequestWithBody(String method, String endpoint, String body, Integer expectedStatusCode) throws Exception { + mockMvc.perform( + request(HttpMethod.valueOf(method), endpoint) + .content(body) + .contentType(APPLICATION_JSON)) + .andExpect(status().is(expectedStatusCode)) + .andExpect(content().string("")); + } - protected void assertRequestWithBody(String method, String endpoint, String body, Integer expectedStatusCode) - throws Exception { - mockMvc - .perform(request(HttpMethod.valueOf(method), endpoint).content(body).contentType(APPLICATION_JSON)) - .andExpect(status().is(expectedStatusCode)) - .andExpect(content().string("")); - } + protected void assertRequest(String method, String endpoint, Integer expectedStatusCode) throws Exception { + mockMvc.perform(request(HttpMethod.valueOf(method), endpoint)) + .andExpect(status().is(expectedStatusCode)) + .andExpect(content().string("")); + } - protected void assertRequest(String method, String endpoint, Integer expectedStatusCode) throws Exception { - mockMvc - .perform(request(HttpMethod.valueOf(method), endpoint)) - .andExpect(status().is(expectedStatusCode)) - .andExpect(content().string("")); - } - - protected void givenISendEventsToTheBus(DomainEvent... domainEvents) { - eventBus.publish(Arrays.asList(domainEvents)); - } + protected void givenISendEventsToTheBus(DomainEvent... domainEvents) { + eventBus.publish(List.of(domainEvents)); + } }