introduce nullable properties (by ?) and drop-line (by ??)
This commit is contained in:
parent
e554f96b14
commit
82900d7a80
@ -1,6 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.scenarios;
|
package net.hostsharing.hsadminng.hs.office.scenarios;
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.scenarios.contact.AmendContactData;
|
||||||
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateExternalDebitorForPartner;
|
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateExternalDebitorForPartner;
|
||||||
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateSelfDebitorForPartner;
|
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateSelfDebitorForPartner;
|
||||||
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateSepaMandateForDebitor;
|
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateSepaMandateForDebitor;
|
||||||
@ -44,7 +45,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
|||||||
@Test
|
@Test
|
||||||
@Order(1010)
|
@Order(1010)
|
||||||
@Produces(explicitly = "Partner: Test AG", implicitly = {"Person: Test AG", "Contact: Test AG - Board of Directors"})
|
@Produces(explicitly = "Partner: Test AG", implicitly = {"Person: Test AG", "Contact: Test AG - Board of Directors"})
|
||||||
void shouldCreatePartner() {
|
void shouldCreateLegalPersonAsPartner() {
|
||||||
new CreatePartner(this)
|
new CreatePartner(this)
|
||||||
.given("partnerNumber", 31010)
|
.given("partnerNumber", 31010)
|
||||||
.given("personType", "LEGAL_PERSON")
|
.given("personType", "LEGAL_PERSON")
|
||||||
@ -55,6 +56,21 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
|||||||
.keep();
|
.keep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1011)
|
||||||
|
@Produces(explicitly = "Partner: Michelle Matthieu", implicitly = {"Person: Michelle Matthieu", "Contact: Michelle Matthieu"})
|
||||||
|
void shouldCreateNaturalPersonAsPartner() {
|
||||||
|
new CreatePartner(this)
|
||||||
|
.given("partnerNumber", 31011)
|
||||||
|
.given("personType", "NATURAL_PERSON")
|
||||||
|
.given("givenName", "Michelle")
|
||||||
|
.given("familyName", "Matthieu")
|
||||||
|
.given("contactCaption", "Michelle Matthieu")
|
||||||
|
.given("emailAddress", "michelle.matthieu@example.org")
|
||||||
|
.doRun()
|
||||||
|
.keep();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1020)
|
@Order(1020)
|
||||||
@Requires("Person: Test AG")
|
@Requires("Person: Test AG")
|
||||||
@ -106,6 +122,22 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
|||||||
.doRun();
|
.doRun();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1100)
|
||||||
|
void shouldAmendContactData() {
|
||||||
|
new AmendContactData(this)
|
||||||
|
.given("partnerNumber", 31020)
|
||||||
|
.doRun();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1101)
|
||||||
|
void shouldReplaceContactData() {
|
||||||
|
new UseCaseNotImplementedYet(this)
|
||||||
|
.given("partnerNumber", 31020)
|
||||||
|
.doRun();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2010)
|
@Order(2010)
|
||||||
@Requires("Partner: Test AG")
|
@Requires("Partner: Test AG")
|
||||||
|
@ -4,8 +4,11 @@ import java.net.URLEncoder;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TemplateResolver {
|
public class TemplateResolver {
|
||||||
|
private final static Pattern pattern = Pattern.compile(",\\s*([}\\]])", Pattern.MULTILINE);
|
||||||
|
|
||||||
enum PlaceholderPrefix {
|
enum PlaceholderPrefix {
|
||||||
RAW('%') {
|
RAW('%') {
|
||||||
@ -55,11 +58,23 @@ public class TemplateResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String resolve() {
|
String resolve() {
|
||||||
copy();
|
final var resolved = copy();
|
||||||
return resolved.toString();
|
final var withoutDroppedLines = removeDroppedLinkes(resolved);
|
||||||
|
final var result = removeSpareCommas(withoutDroppedLines);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copy() {
|
private static String removeSpareCommas(final String withoutDroppedLines) {
|
||||||
|
return pattern.matcher(withoutDroppedLines).replaceAll("$1");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String removeDroppedLinkes(final String text) {
|
||||||
|
return Arrays.stream(text.split("\n"))
|
||||||
|
.filter(line -> !line.contains("<<<drop line>>"))
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String copy() {
|
||||||
while (hasMoreChars()) {
|
while (hasMoreChars()) {
|
||||||
if (PlaceholderPrefix.contains(currentChar()) && nextChar() == '{') {
|
if (PlaceholderPrefix.contains(currentChar()) && nextChar() == '{') {
|
||||||
startPlaceholder(currentChar());
|
startPlaceholder(currentChar());
|
||||||
@ -67,6 +82,7 @@ public class TemplateResolver {
|
|||||||
resolved.append(fetchChar());
|
resolved.append(fetchChar());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return resolved.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasMoreChars() {
|
private boolean hasMoreChars() {
|
||||||
@ -97,6 +113,18 @@ public class TemplateResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object propVal(final String name) {
|
private Object propVal(final String name) {
|
||||||
|
if (name.endsWith("??")) {
|
||||||
|
final String pureName = name.substring(0, name.length() - "??".length());
|
||||||
|
final var val = properties.get(pureName);
|
||||||
|
if (val == null) {
|
||||||
|
return "<<<drop line>>";
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
if (name.endsWith("?")) {
|
||||||
|
final String pureName = name.substring(0, name.length() - "?".length());
|
||||||
|
return properties.get(pureName);
|
||||||
|
}
|
||||||
final var val = properties.get(name);
|
final var val = properties.get(name);
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
throw new IllegalStateException("Missing required property: " + name);
|
throw new IllegalStateException("Missing required property: " + name);
|
||||||
@ -144,6 +172,7 @@ public class TemplateResolver {
|
|||||||
|
|
||||||
private static String jsonQuoted(final Object value) {
|
private static String jsonQuoted(final Object value) {
|
||||||
return switch (value) {
|
return switch (value) {
|
||||||
|
case null -> null;
|
||||||
case Boolean bool -> bool.toString();
|
case Boolean bool -> bool.toString();
|
||||||
case Number number -> number.toString();
|
case Number number -> number.toString();
|
||||||
case String string -> "\"" + string.replace("\n", "\\n") + "\"";
|
case String string -> "\"" + string.replace("\n", "\\n") + "\"";
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.scenarios;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||||
|
|
||||||
|
public class UseCaseNotImplementedYet extends UseCase<UseCaseNotImplementedYet> {
|
||||||
|
|
||||||
|
public UseCaseNotImplementedYet(final ScenarioTest testSuite) {
|
||||||
|
super(testSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HttpResponse run() {
|
||||||
|
assumeThat(false).isTrue(); // makes the test gray
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.scenarios.contact;
|
||||||
|
|
||||||
|
import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.scenarios.UseCase;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||||
|
|
||||||
|
public class AmendContactData extends UseCase<AmendContactData> {
|
||||||
|
|
||||||
|
public AmendContactData(final ScenarioTest testSuite) {
|
||||||
|
super(testSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HttpResponse run() {
|
||||||
|
assumeThat(false).isTrue(); // makes the test gray
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -28,17 +28,19 @@ public class CreatePartner extends UseCase<CreatePartner> {
|
|||||||
"Even in production data we expect this query to return just a single result." // TODO.impl: add constraint?
|
"Even in production data we expect this query to return just a single result." // TODO.impl: add constraint?
|
||||||
);
|
);
|
||||||
|
|
||||||
obtain("Person: %{tradeName}", () ->
|
obtain("Partner-Person", () ->
|
||||||
httpPost("/api/hs/office/persons", usingJsonBody("""
|
httpPost("/api/hs/office/persons", usingJsonBody("""
|
||||||
{
|
{
|
||||||
"personType": ${personType},
|
"personType": ${personType},
|
||||||
"tradeName": ${tradeName}
|
"tradeName": ${tradeName??},
|
||||||
|
"givenName": ${givenName??},
|
||||||
|
"familyName": ${familyName??}
|
||||||
}
|
}
|
||||||
"""))
|
"""))
|
||||||
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
|
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
|
||||||
);
|
);
|
||||||
|
|
||||||
obtain("Contact: %{tradeName} - Board of Directors", () ->
|
obtain("Contact: %{contactCaption}", () ->
|
||||||
httpPost("/api/hs/office/contacts", usingJsonBody("""
|
httpPost("/api/hs/office/contacts", usingJsonBody("""
|
||||||
{
|
{
|
||||||
"caption": ${contactCaption},
|
"caption": ${contactCaption},
|
||||||
@ -55,8 +57,8 @@ public class CreatePartner extends UseCase<CreatePartner> {
|
|||||||
"partnerNumber": ${partnerNumber},
|
"partnerNumber": ${partnerNumber},
|
||||||
"partnerRel": {
|
"partnerRel": {
|
||||||
"anchorUuid": ${Person: Hostsharing eG},
|
"anchorUuid": ${Person: Hostsharing eG},
|
||||||
"holderUuid": ${Person: %{tradeName}},
|
"holderUuid": ${Partner-Person},
|
||||||
"contactUuid": ${Contact: %{tradeName} - Board of Directors}
|
"contactUuid": ${Contact: %{contactCaption}}
|
||||||
},
|
},
|
||||||
"details": {
|
"details": {
|
||||||
"registrationOffice": "Registergericht Hamburg",
|
"registrationOffice": "Registergericht Hamburg",
|
||||||
|
Loading…
Reference in New Issue
Block a user