-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cancel event * Event handler and parser for the event are hooked up * Added unit test for the parser * Sonar warnings * unit test for the event dispatcher
- Loading branch information
1 parent
fca1758
commit cdb9c9f
Showing
9 changed files
with
309 additions
and
31 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/com/appdirect/sdk/appmarket/events/AddonSubscriptionCancel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.appdirect.sdk.appmarket.events; | ||
|
||
import java.util.Map; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
|
||
/** | ||
* A developer-facing event representing cancellation of an addon account requested by the AppMarket | ||
*/ | ||
@Value | ||
@EqualsAndHashCode(callSuper = true) | ||
public class AddonSubscriptionCancel extends EventWithConsumerKeyQueryParametersAndEventFlag { | ||
private final String accountIdentifier; | ||
private final String parentAccountIdentifier; | ||
|
||
public AddonSubscriptionCancel(String accountIdentifier, | ||
String parentAccountIdentifier, | ||
String consumerKeyUsedByTheRequest, | ||
Map<String, String[]> queryParameters, | ||
EventFlag flag) { | ||
|
||
super(consumerKeyUsedByTheRequest, queryParameters, flag); | ||
this.accountIdentifier = accountIdentifier; | ||
this.parentAccountIdentifier = parentAccountIdentifier; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/appdirect/sdk/appmarket/events/AddonSubscriptionCancelEventParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.appdirect.sdk.appmarket.events; | ||
|
||
class AddonSubscriptionCancelEventParser implements EventParser<AddonSubscriptionCancel> { | ||
@Override | ||
public AddonSubscriptionCancel parse(EventInfo eventInfo, EventHandlingContext eventContext) { | ||
return new AddonSubscriptionCancel( | ||
eventInfo.getPayload().getAccount().getAccountIdentifier(), | ||
eventInfo.getPayload().getAccount().getParentAccountIdentifier(), | ||
eventContext.getConsumerKeyUsedByTheRequest(), | ||
eventContext.getQueryParameters(), | ||
eventInfo.getFlag() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/test/java/com/appdirect/sdk/appmarket/events/AddonSubscriptionCancelEventParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.appdirect.sdk.appmarket.events; | ||
|
||
import static com.appdirect.sdk.appmarket.events.EventFlag.STATELESS; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class AddonSubscriptionCancelEventParserTest { | ||
|
||
AddonSubscriptionCancelEventParser testedParser = new AddonSubscriptionCancelEventParser(); | ||
|
||
@Test | ||
public void parse_whenAnAddonSubscriptionCancelEventWithNoFlagIsParsed_aCorrespondingRichEventIsCreated() throws Exception { | ||
//Given | ||
String expectedConsumerKey = "expectedConsumerKey"; | ||
String expectedAddonAccountIdentifier = "expectedAddonAccountIdentifier"; | ||
String expectedParentAccountIdentifier = "expectedParentAccountIdentifier"; | ||
Map<String, String[]> expectedParameters = new HashMap<>(); | ||
EventFlag expectedFlag = null; | ||
EventInfo testEvent = addonCancelEvent(expectedAddonAccountIdentifier, expectedParentAccountIdentifier, expectedFlag); | ||
EventHandlingContext testEventContext = EventHandlingContexts.eventContext(expectedConsumerKey, expectedParameters); | ||
AddonSubscriptionCancel expectedEvent = new AddonSubscriptionCancel( | ||
expectedAddonAccountIdentifier, | ||
expectedParentAccountIdentifier, | ||
expectedConsumerKey, | ||
expectedParameters, | ||
expectedFlag | ||
); | ||
|
||
//When | ||
AddonSubscriptionCancel parsedEvent = testedParser.parse(testEvent, testEventContext); | ||
|
||
//Then | ||
assertThat(parsedEvent).isEqualTo(expectedEvent); | ||
} | ||
|
||
@Test | ||
public void parse_whenAnAddonSubscriptionCancelEventWithFlagIsParsed_aCorrespondingRichEventIsCreated() throws Exception { | ||
//Given | ||
String expectedConsumerKey = "expectedConsumerKey"; | ||
String expectedAddonAccountIdentifier = "expectedAddonAccountIdentifier"; | ||
String expectedParentAccountIdentifier = "expectedParentAccountIdentifier"; | ||
Map<String, String[]> expectedParameters = new HashMap<>(); | ||
EventFlag expectedFlag = STATELESS; | ||
EventInfo testEvent = addonCancelEvent(expectedAddonAccountIdentifier, expectedParentAccountIdentifier, expectedFlag); | ||
EventHandlingContext testEventContext = EventHandlingContexts.eventContext(expectedConsumerKey, expectedParameters); | ||
AddonSubscriptionCancel expectedEvent = new AddonSubscriptionCancel( | ||
expectedAddonAccountIdentifier, | ||
expectedParentAccountIdentifier, | ||
expectedConsumerKey, | ||
expectedParameters, | ||
expectedFlag | ||
); | ||
|
||
//When | ||
AddonSubscriptionCancel parsedEvent = testedParser.parse(testEvent, testEventContext); | ||
|
||
//Then | ||
assertThat(parsedEvent).isEqualTo(expectedEvent); | ||
} | ||
|
||
private EventInfo addonCancelEvent(String accountIdentifier, String parentAccountIdentidier, EventFlag eventFlag) { | ||
return EventInfo.builder() | ||
.flag(eventFlag) | ||
.payload( | ||
EventPayload.builder() | ||
.account( | ||
AccountInfo.builder() | ||
.accountIdentifier(accountIdentifier) | ||
.parentAccountIdentifier(parentAccountIdentidier) | ||
.build() | ||
).build() | ||
).build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...est/java/com/appdirect/sdk/feature/CanDispatchAddonSubscriptionCancelIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.appdirect.sdk.feature; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.util.EntityUtils; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.context.embedded.LocalServerPort; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import com.appdirect.sdk.support.FakeAppmarket; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = MinimalConnector.class, webEnvironment = RANDOM_PORT) | ||
public class CanDispatchAddonSubscriptionCancelIntegrationTest { | ||
@LocalServerPort | ||
private int localConnectorPort; | ||
private FakeAppmarket fakeAppmarket; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
fakeAppmarket = FakeAppmarket.create(localConnectorPort + 1, "isv-key", "isv-secret").start(); | ||
} | ||
|
||
@After | ||
public void stop() throws Exception { | ||
fakeAppmarket.stop(); | ||
} | ||
|
||
@Test | ||
public void addonSubscriptionOrderIsProcessedSuccessfully() throws Exception { | ||
HttpResponse response = fakeAppmarket.sendEventTo(connectorEventEndpoint(), "/v1/events/subscription-cancel-addon"); | ||
|
||
assertThat(fakeAppmarket.allRequestPaths()).first().isEqualTo("/v1/events/subscription-cancel-addon"); | ||
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(202); | ||
assertThat(EntityUtils.toString(response.getEntity())).isEqualTo("{\"success\":true,\"message\":\"Event with eventId=subscription-cancel-addon has been accepted by the connector. It will be processed soon.\"}"); | ||
|
||
fakeAppmarket.waitForResolvedEvents(1); | ||
assertThat(fakeAppmarket.resolvedEvents()).contains("subscription-cancel-addon"); | ||
assertThat(fakeAppmarket.allRequestPaths()).last().isEqualTo("/api/integration/v1/events/subscription-cancel-addon/result"); | ||
assertThat(fakeAppmarket.lastRequestBody()).isEqualTo("{\"success\":true,\"message\":\"ADDON_CANCEL has been processed just now.\"}"); | ||
} | ||
|
||
private String connectorEventEndpoint() { | ||
return baseConnectorUrl() + "/api/v1/integration/processEvent"; | ||
} | ||
|
||
private String baseConnectorUrl() { | ||
return "http://localhost:" + localConnectorPort; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.