Compare commits

...

2 Commits

Author SHA1 Message Date
Michael Hoennig
ff42bc45ab add RestTest for findMembershipByNonExistingMemberNumberReturnsEmptyList 2024-11-13 14:56:44 +01:00
Michael Hoennig
11f6a895f2 add introductory text for partner as client 2024-11-13 14:22:10 +01:00
4 changed files with 42 additions and 3 deletions

View File

@ -20,6 +20,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.UUID; import java.util.UUID;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@ -44,8 +45,36 @@ public class HsOfficeMembershipControllerRestTest {
@MockBean @MockBean
EntityManagerWrapper em; EntityManagerWrapper em;
@Nested
class GetMemberships {
@Test
void findMembershipByNonExistingMemberNumberReturnsEmptyList() throws Exception {
// when
mockMvc.perform(MockMvcRequestBuilders
.get("/api/hs/office/memberships?memberNumber=12345")
.header("current-subject", "superuser-alex@hostsharing.net")
.contentType(MediaType.APPLICATION_JSON)
.content("""
{
"partner.uuid": null,
"memberNumberSuffix": "01",
"validFrom": "2022-10-13",
"membershipFeeBillable": "true"
}
""")
.accept(MediaType.APPLICATION_JSON))
// then
.andExpect(status().is2xxSuccessful())
.andExpect(jsonPath("$", hasSize(0)));
}
}
@Nested @Nested
class AddMembership { class AddMembership {
@Test @Test
void respondBadRequest_ifPartnerUuidIsMissing() throws Exception { void respondBadRequest_ifPartnerUuidIsMissing() throws Exception {
@ -98,7 +127,9 @@ public class HsOfficeMembershipControllerRestTest {
.andExpect(status().is4xxClientError()) .andExpect(status().is4xxClientError())
.andExpect(jsonPath("statusCode", is(400))) .andExpect(jsonPath("statusCode", is(400)))
.andExpect(jsonPath("statusPhrase", is("Bad Request"))) .andExpect(jsonPath("statusPhrase", is("Bad Request")))
.andExpect(jsonPath("message", is("ERROR: [400] Unable to find Partner by partner.uuid: " + givenPartnerUuid))); .andExpect(jsonPath(
"message",
is("ERROR: [400] Unable to find Partner by partner.uuid: " + givenPartnerUuid)));
} }
@ParameterizedTest @ParameterizedTest

View File

@ -18,7 +18,6 @@ public class PathAssertion {
public Consumer<UseCase.HttpResponse> contains(final String resolvableValue) { public Consumer<UseCase.HttpResponse> contains(final String resolvableValue) {
return response -> { return response -> {
try { try {
// FIXME: typed check instead of .map(Object::toString) possible?
response.path(path).map(Object::toString).contains(ScenarioTest.resolve(resolvableValue)); response.path(path).map(Object::toString).contains(ScenarioTest.resolve(resolvableValue));
} catch (final AssertionError e) { } catch (final AssertionError e) {
// without this, the error message is often lacking important context // without this, the error message is often lacking important context

View File

@ -51,6 +51,7 @@ public abstract class UseCase<T extends UseCase<?>> {
private final Map<String, Object> givenProperties = new LinkedHashMap<>(); private final Map<String, Object> givenProperties = new LinkedHashMap<>();
private String nextTitle; // just temporary to override resultAlias for sub-use-cases private String nextTitle; // just temporary to override resultAlias for sub-use-cases
private String introduction;
public UseCase(final ScenarioTest testSuite) { public UseCase(final ScenarioTest testSuite) {
this(testSuite, getResultAliasFromProducesAnnotationInCallStack()); this(testSuite, getResultAliasFromProducesAnnotationInCallStack());
@ -72,6 +73,9 @@ public abstract class UseCase<T extends UseCase<?>> {
} }
public final HttpResponse doRun() { public final HttpResponse doRun() {
if (introduction != null) {
testReport.printPara(introduction);
}
testReport.printPara("### Given Properties"); testReport.printPara("### Given Properties");
testReport.printLine(""" testReport.printLine("""
| name | value | | name | value |
@ -96,6 +100,11 @@ public abstract class UseCase<T extends UseCase<?>> {
protected void verify(final HttpResponse response) { protected void verify(final HttpResponse response) {
} }
public UseCase<T> introduction(final String introduction) {
this.introduction = introduction;
return this;
}
public final UseCase<T> given(final String propName, final Object propValue) { public final UseCase<T> given(final String propName, final Object propValue) {
givenProperties.put(propName, propValue); givenProperties.put(propName, propValue);
ScenarioTest.putProperty(propName, propValue); ScenarioTest.putProperty(propName, propValue);

View File

@ -17,7 +17,7 @@ public class CreatePartner extends UseCase<CreatePartner> {
public CreatePartner(final ScenarioTest testSuite) { public CreatePartner(final ScenarioTest testSuite) {
super(testSuite); super(testSuite);
// FIXME: Anmerkung, dass alle Partner Kunden sind introduction("A partner can be a client or a vendor, currently we only use them for clients.");
} }
@Override @Override