Compare commits

..

3 Commits

Author SHA1 Message Date
Michael Hoennig
31f5bcc5d8 explicitly fetch Test AG in AddRepresentativeToPartner 2024-10-29 17:56:31 +01:00
Michael Hoennig
6b30d0f6f9 explicitly fetch Hostsharing eG in CreatePartner 2024-10-29 17:44:02 +01:00
Michael Hoennig
77cf97ded9 fix missing status 2024-10-29 17:43:46 +01:00
5 changed files with 29 additions and 12 deletions

View File

@ -61,7 +61,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Produces("Representative: Tracy Trust for Test AG")
void shouldAddRepresentativeToPartner() {
new AddRepresentativeToPartner(this)
.given("partnerPersonUuid", "%{Person: Test AG}")
.given("partnerPersonTradeName", "Test AG")
.given("representativeFamilyName", "Trust")
.given("representativeGivenName", "Tracy")
.given("representativePostalAddress", """

View File

@ -16,9 +16,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestReport {
private final Map<String, ?> aliases;
private final StringBuilder debugLog = new StringBuilder(); // records everything for debugging purposes
private final StringBuilder markdownLog = new StringBuilder(); // records everything for debugging purposes
private PrintWriter markdownFile;
private PrintWriter markdownReport;
private int silent; // do not print anything to test-report if >0
public TestReport(final Map<String, ?> aliases) {
@ -29,22 +29,22 @@ public class TestReport {
final var testMethodName = testInfo.getTestMethod().map(Method::getName).orElseThrow();
final var testMethodOrder = testInfo.getTestMethod().map(m -> m.getAnnotation(Order.class).value()).orElseThrow();
assertThat(new File("doc/scenarios/").isDirectory() || new File("doc/scenarios/").mkdirs()).as("mkdir doc/scenarios/").isTrue();
markdownFile = new PrintWriter(new FileWriter("doc/scenarios/" + testMethodOrder + "-" + testMethodName + ".md"));
markdownReport = new PrintWriter(new FileWriter("doc/scenarios/" + testMethodOrder + "-" + testMethodName + ".md"));
print("## Scenario: " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2"));
}
@SneakyThrows
public void print(final String output) {
final var outputWithCommentsForUuids = appendUUIDKey(output.replace("+", "\\+"));
final var outputWithCommentsForUuids = appendUUIDKey(output);
// for tests executed due to @Requires/@Produces there is no markdownFile yet
if (silent == 0) {
markdownFile.print(outputWithCommentsForUuids);
if (markdownReport != null && silent == 0) {
markdownReport.print(outputWithCommentsForUuids);
}
// but the debugLog should contain all output, even if silent
debugLog.append(outputWithCommentsForUuids);
markdownLog.append(outputWithCommentsForUuids);
}
public void printLine(final String output) {
@ -56,7 +56,7 @@ public class TestReport {
}
public void close() {
markdownFile.close();
markdownReport.close();
}
private String appendUUIDKey(String multilineText) {

View File

@ -281,8 +281,8 @@ public abstract class UseCase<T extends UseCase<?>> {
testReport.printLine(httpMethod.name() + " " + uri);
testReport.printLine((requestBody != null ? requestBody.trim() : ""));
// the response + "=> status: " + status + " " +
testReport.printLine(locationUuid != null ? locationUuid.toString() : "");
// the response
testReport.printLine("=> status: " + status + " " + (locationUuid != null ? locationUuid : ""));
if (httpMethod == HttpMethod.GET || status.isError()) {
final var jsonNode = objectMapper.readTree(response.body());
final var prettyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);

View File

@ -7,6 +7,7 @@ import org.springframework.http.HttpStatus;
import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
public class AddRepresentativeToPartner extends UseCase<AddRepresentativeToPartner> {
@ -16,6 +17,13 @@ public class AddRepresentativeToPartner extends UseCase<AddRepresentativeToPartn
@Override
protected HttpResponse run() {
keep("Person: %{partnerPersonTradeName}", () ->
httpGet("/api/hs/office/persons?name=" + uriEncoded("%{partnerPersonTradeName}"))
.expecting(OK).expecting(JSON),
response -> response.expectArrayElements(1).getFromBody("[0].uuid")
);
keep("Person: %{representativeGivenName} %{representativeFamilyName}", () ->
httpPost("/api/hs/office/persons", usingJsonBody("""
{
@ -49,7 +57,7 @@ public class AddRepresentativeToPartner extends UseCase<AddRepresentativeToPartn
return httpPost("/api/hs/office/relations", usingJsonBody("""
{
"type": "REPRESENTATIVE",
"anchorUuid": ${partnerPersonUuid},
"anchorUuid": ${Person: %{partnerPersonTradeName}},
"holderUuid": ${Person: %{representativeGivenName} %{representativeFamilyName}},
"contactUuid": ${Contact: %{representativeGivenName} %{representativeFamilyName}}
}

View File

@ -5,6 +5,9 @@ import net.hostsharing.hsadminng.hs.office.scenarios.UseCase;
import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest;
import org.springframework.http.HttpStatus;
import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.OK;
public class CreatePartner extends UseCase<CreatePartner> {
public CreatePartner(final ScenarioTest testSuite, final String resultAlias) {
@ -18,6 +21,12 @@ public class CreatePartner extends UseCase<CreatePartner> {
@Override
protected HttpResponse run() {
keep("Person: Hostsharing eG", () ->
httpGet("/api/hs/office/persons?name=Hostsharing+eG")
.expecting(OK).expecting(JSON),
response -> response.expectArrayElements(1).getFromBody("[0].uuid")
);
keep("Person: %{tradeName}", () ->
httpPost("/api/hs/office/persons", usingJsonBody("""
{