-
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.
PI-6525: AddonDetector uses parentAccountIdentifier field (#43)
* PI-6525: updated the AddonDetector so it uses a better heuristic: instead of checking for edition codes, it simply checks for the presence of the payload.account.parentAccountIdentifier field. This field is only filled for add-on v2 related events. * Review: line breaks!
- Loading branch information
1 parent
eadbdc0
commit fca1758
Showing
9 changed files
with
62 additions
and
97 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/appdirect/sdk/appmarket/events/AddonEventDetector.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,23 @@ | ||
package com.appdirect.sdk.appmarket.events; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Determines if an event is related to an add-on subscription or to a regular subscription. | ||
* This is used to dispatch the add-on events to the add-on event handlers. | ||
*/ | ||
public class AddonEventDetector { | ||
|
||
/** | ||
* Determines if a given event is related to an add-on subscription or not. | ||
* | ||
* @param rawEvent the event to check; can't be null. | ||
* @return <code>true</code> if the event is related to an add-on subscription; <code>false</code> otherwise. | ||
*/ | ||
public boolean eventIsRelatedToAddon(EventInfo rawEvent) { | ||
return Optional.ofNullable(rawEvent.getPayload()) | ||
.map(EventPayload::getAccount) | ||
.map(AccountInfo::getParentAccountIdentifier) | ||
.isPresent(); | ||
} | ||
} |
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
32 changes: 0 additions & 32 deletions
32
src/main/java/com/appdirect/sdk/appmarket/events/EditionCodeBasedAddonDetector.java
This file was deleted.
Oops, something went wrong.
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
32 changes: 32 additions & 0 deletions
32
src/test/java/com/appdirect/sdk/appmarket/events/AddonEventDetectorTest.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,32 @@ | ||
package com.appdirect.sdk.appmarket.events; | ||
|
||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
public class AddonEventDetectorTest { | ||
private AddonEventDetector addonDetector = new AddonEventDetector(); | ||
|
||
@Test | ||
public void eventIsFlaggedAsAddonRelated_whenParentAccountId_isPresent() throws Exception { | ||
assertThat(addonDetector.eventIsRelatedToAddon(anEventWithParentAccountId())).isTrue(); | ||
} | ||
|
||
@Test | ||
public void eventIsNotFlaggedAsAddonRelated_whenParentAccountId_isAbsent() throws Exception { | ||
assertThat(addonDetector.eventIsRelatedToAddon(anEventWithNoParentAccountId())).isFalse(); | ||
} | ||
|
||
private EventInfo anEventWithParentAccountId() { | ||
return EventInfo.builder() | ||
.payload(EventPayload.builder() | ||
.account(AccountInfo.builder().parentAccountIdentifier("some-parent-account-id").build()) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
private EventInfo anEventWithNoParentAccountId() { | ||
return EventInfo.builder().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
41 changes: 0 additions & 41 deletions
41
src/test/java/com/appdirect/sdk/appmarket/events/EditionCodeBasedAddonDetectorTest.java
This file was deleted.
Oops, something went wrong.
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