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)); + } } diff --git a/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java b/src/backoffice/test/tv/codely/backoffice/BackofficeContextInfrastructureTestCase.java index efbad4e7..ff1aa571 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,10 @@ 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"); } } +//Add the logging function 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); }