Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions apps/test/tv/codely/apps/ApplicationTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
import tv.codely.shared.infrastructure.InfrastructureTestCase;

import java.io.IOException;
import java.util.logging.Logger;

@ContextConfiguration(classes = BackofficeFrontendApplication.class)
@SpringBootTest
public abstract class BackofficeContextInfrastructureTestCase extends InfrastructureTestCase {
@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
13 changes: 6 additions & 7 deletions src/shared/main/tv/codely/shared/domain/StringValueObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
Expand Down