subscription tests
This commit is contained in:
parent
5605e8a8c1
commit
adfa95bf0e
@ -10,6 +10,8 @@ import net.hostsharing.hsadminng.hs.office.usecases.membership.CreateMembership;
|
|||||||
import net.hostsharing.hsadminng.hs.office.usecases.partner.CreatePartner;
|
import net.hostsharing.hsadminng.hs.office.usecases.partner.CreatePartner;
|
||||||
import net.hostsharing.hsadminng.hs.office.usecases.debitor.DeleteDebitor;
|
import net.hostsharing.hsadminng.hs.office.usecases.debitor.DeleteDebitor;
|
||||||
import net.hostsharing.hsadminng.hs.office.usecases.partner.DeletePartner;
|
import net.hostsharing.hsadminng.hs.office.usecases.partner.DeletePartner;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.usecases.subscription.SubscribeToMailinglist;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.usecases.subscription.UnsubscribeFromMailinglist;
|
||||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||||
import org.junit.jupiter.api.MethodOrderer;
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
@ -132,7 +134,7 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3000)
|
@Order(4000)
|
||||||
@Requires("Partner: Test AG")
|
@Requires("Partner: Test AG")
|
||||||
void shouldCreateMembershipForPartner() {
|
void shouldCreateMembershipForPartner() {
|
||||||
new CreateMembership(this)
|
new CreateMembership(this)
|
||||||
@ -142,4 +144,28 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
|||||||
.given("membershipFeeBillable", "true")
|
.given("membershipFeeBillable", "true")
|
||||||
.doRun();
|
.doRun();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(5000)
|
||||||
|
@Requires("Person: Test AG")
|
||||||
|
@Produces("Subscription: Michael Miller to operations-announce")
|
||||||
|
void shouldSubscribeNewPersonAndContactToMailinglist() {
|
||||||
|
new SubscribeToMailinglist(this)
|
||||||
|
.given("partnerPersonUuid", "%{Person: Test AG}")
|
||||||
|
.given("subscriberFamilyName", "Miller")
|
||||||
|
.given("subscriberGivenName", "Michael")
|
||||||
|
.given("subscriberEMailAddress", "michael.miller@example.org")
|
||||||
|
.given("mailingList", "operations-announce")
|
||||||
|
.doRun()
|
||||||
|
.keep();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(5001)
|
||||||
|
@Requires("Subscription: Michael Miller to operations-announce")
|
||||||
|
void shouldUnsubscribeNewPersonAndContactToMailinglist() {
|
||||||
|
new UnsubscribeFromMailinglist(this)
|
||||||
|
.given("subscriptionUuid", "%{Subscription: Michael Miller to operations-announce}")
|
||||||
|
.doRun();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ public class TemplateResolver {
|
|||||||
|
|
||||||
private char currentChar() {
|
private char currentChar() {
|
||||||
if (position >= template.length()) {
|
if (position >= template.length()) {
|
||||||
throw new IllegalStateException("no more characters. resolved so far: " + resolved);
|
throw new IllegalStateException("no more characters, maybe closing bracelet missing in template: '''\n" + template + "\n'''");
|
||||||
}
|
}
|
||||||
return template.charAt(position);
|
return template.charAt(position);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final UUID uuid(final String alias) {
|
public final UUID uuid(final String alias) {
|
||||||
return UseCaseTest.getAlias(alias).uuid();
|
return UseCaseTest.uuid(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class JsonTemplate {
|
public static class JsonTemplate {
|
||||||
|
@ -29,6 +29,7 @@ import java.util.UUID;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Optional.ofNullable;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public abstract class UseCaseTest extends ContextBasedTest {
|
public abstract class UseCaseTest extends ContextBasedTest {
|
||||||
@ -151,10 +152,10 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
|||||||
return aliases.containsKey(alias);
|
return aliases.containsKey(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Alias<?> getAlias(final String name) {
|
static UUID uuid(final String name) {
|
||||||
final var alias = aliases.get(name);
|
final UUID alias = ofNullable(knowVariables().get(name)).filter(v -> v instanceof UUID).map(UUID.class::cast).orElse(null);
|
||||||
assertThat(alias).as("alias '" + name + "' not found in aliases [" +
|
assertThat(alias).as("alias '" + name + "' not found in aliases nor in properties [" +
|
||||||
aliases.keySet().stream().map(v -> "'" + v + "'").collect(Collectors.joining(", ")) + "]"
|
knowVariables().keySet().stream().map(v -> "'" + v + "'").collect(Collectors.joining(", ")) + "]"
|
||||||
).isNotNull();
|
).isNotNull();
|
||||||
return alias;
|
return alias;
|
||||||
}
|
}
|
||||||
@ -164,7 +165,7 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void putProperty(final String name, final Object value) {
|
static void putProperty(final String name, final Object value) {
|
||||||
properties.put(name, (value instanceof String string) ? resolve(string) : value);
|
properties.put(name, (value instanceof String string) ? resolveTyped(string) : value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, Object> knowVariables() {
|
static Map<String, Object> knowVariables() {
|
||||||
@ -179,4 +180,14 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
|||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Object resolveTyped(final String text) {
|
||||||
|
final var resolved = resolve(text);
|
||||||
|
try {
|
||||||
|
return UUID.fromString(resolved);
|
||||||
|
} catch (final IllegalArgumentException e) {
|
||||||
|
// ignore and just use the String value
|
||||||
|
}
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.usecases.subscription;
|
||||||
|
|
||||||
|
import io.restassured.http.ContentType;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.usecases.UseCase;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.usecases.UseCaseTest;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
import static io.restassured.http.ContentType.JSON;
|
||||||
|
import static org.springframework.http.HttpStatus.CREATED;
|
||||||
|
|
||||||
|
public class SubscribeToMailinglist extends UseCase<SubscribeToMailinglist> {
|
||||||
|
|
||||||
|
public SubscribeToMailinglist(final UseCaseTest testSuite) {
|
||||||
|
super(testSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HttpResponse run() {
|
||||||
|
keep("Person: %{subscriberGivenName} %{subscriberFamilyName}", () ->
|
||||||
|
httpPost("/api/hs/office/persons", usingJsonBody("""
|
||||||
|
{
|
||||||
|
"personType": "NATURAL_PERSON",
|
||||||
|
"familyName": ${subscriberFamilyName},
|
||||||
|
"givenName": ${subscriberGivenName}
|
||||||
|
}
|
||||||
|
"""))
|
||||||
|
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
|
||||||
|
);
|
||||||
|
|
||||||
|
keep("Contact: %{subscriberGivenName} %{subscriberFamilyName}", () ->
|
||||||
|
httpPost("/api/hs/office/contacts", usingJsonBody("""
|
||||||
|
{
|
||||||
|
"caption": "%{subscriberGivenName} %{subscriberFamilyName}",
|
||||||
|
"emailAddresses": {
|
||||||
|
"main": ${subscriberEMailAddress}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""))
|
||||||
|
.expecting(CREATED).expecting(JSON)
|
||||||
|
);
|
||||||
|
|
||||||
|
return httpPost("/api/hs/office/relations", usingJsonBody("""
|
||||||
|
{
|
||||||
|
"type": "SUBSCRIBER",
|
||||||
|
"mark": ${mailingList},
|
||||||
|
"anchorUuid": ${partnerPersonUuid},
|
||||||
|
"holderUuid": ${Person: %{subscriberGivenName} %{subscriberFamilyName}},
|
||||||
|
"contactUuid": ${Contact: %{subscriberGivenName} %{subscriberFamilyName}}
|
||||||
|
}
|
||||||
|
"""))
|
||||||
|
.expecting(CREATED).expecting(JSON);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.usecases.subscription;
|
||||||
|
|
||||||
|
import net.hostsharing.hsadminng.hs.office.usecases.UseCase;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.usecases.UseCaseTest;
|
||||||
|
|
||||||
|
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||||
|
|
||||||
|
public class UnsubscribeFromMailinglist extends UseCase<UnsubscribeFromMailinglist> {
|
||||||
|
|
||||||
|
public UnsubscribeFromMailinglist(final UseCaseTest testSuite) {
|
||||||
|
super(testSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HttpResponse run() {
|
||||||
|
|
||||||
|
return httpDelete("/api/hs/office/relations/" + uuid("subscriptionUuid"))
|
||||||
|
.expecting(NO_CONTENT);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user