Skip to content

Commit

Permalink
Merge pull request #5950 from UdeshAthukorala/mores-test-xacml
Browse files Browse the repository at this point in the history
Add more unit tests for Subscriber Persistence Manager classes
  • Loading branch information
UdeshAthukorala authored Sep 24, 2024
2 parents 3f79301 + d8fe740 commit 502bd71
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertThrows;
import static org.wso2.carbon.identity.entitlement.common.EntitlementConstants.PDP_SUBSCRIBER_ID;

/**
* This class tests the behavior of the Subscriber Persistence Manager class.
Expand Down Expand Up @@ -70,6 +71,7 @@ public abstract class SubscriberPersistenceManagerTest {
public PublisherDataHolder sampleHolder1;
public PublisherDataHolder sampleHolder2;
public PublisherDataHolder updatedSampleHolder1;
public PublisherDataHolder invalidSampleHolder;

@BeforeClass
public void setUpClass() throws Exception {
Expand Down Expand Up @@ -97,6 +99,7 @@ public void setUp() {
updatedSampleHolder1 =
createSampleHolder(SAMPLE_SUBSCRIBER_ID_1, SAMPLE_SUBSCRIBER_URL_2, SAMPLE_SUBSCRIBER_USERNAME_2,
SAMPLE_SUBSCRIBER_PASSWORD_2);
invalidSampleHolder = createSampleHolder(null, null, null, null);
}

@AfterMethod
Expand Down Expand Up @@ -135,8 +138,24 @@ public void testAddSubscriber() throws Exception {
SAMPLE_SUBSCRIBER_PASSWORD_1);
}

@Test(priority = 1)
public void testAddInvalidSubscriber() throws Exception {

assertThrows(EntitlementException.class, () -> subscriberPersistenceManager.addSubscriber(invalidSampleHolder));
}

@Test(priority = 1)
public void testAddSubscriberWithDuplicateId() throws Exception {

subscriberPersistenceManager.addSubscriber(sampleHolder1);
assertThrows(EntitlementException.class, () -> subscriberPersistenceManager.addSubscriber(sampleHolder1));
}

@Test(priority = 2)
public void listSubscriberIds() throws Exception {
public void testListSubscriberIds() throws Exception {

List<String> subscriberIds = subscriberPersistenceManager.listSubscriberIds("*");
assertEquals(subscriberIds.size(), 0);

subscriberPersistenceManager.addSubscriber(sampleHolder1);
subscriberPersistenceManager.addSubscriber(sampleHolder2);
Expand Down Expand Up @@ -174,6 +193,13 @@ public void testUpdateSubscriber() throws Exception {
SAMPLE_SUBSCRIBER_PASSWORD_2);
}

@Test(priority = 3)
public void testUpdateInvalidSubscriber() throws Exception {

assertThrows(EntitlementException.class,
() -> subscriberPersistenceManager.updateSubscriber(invalidSampleHolder));
}

@Test(priority = 4)
public void testRemoveSubscriber() throws Exception {

Expand All @@ -183,6 +209,14 @@ public void testRemoveSubscriber() throws Exception {
() -> subscriberPersistenceManager.getSubscriber(SAMPLE_SUBSCRIBER_ID_1, false));
}

@Test(priority = 4)
public void testRemoveInvalidSubscriber() {

assertThrows(EntitlementException.class, () -> subscriberPersistenceManager.removeSubscriber(null));
assertThrows(EntitlementException.class,
() -> subscriberPersistenceManager.removeSubscriber(PDP_SUBSCRIBER_ID));
}

private void mockSecretEncryption(String secret) throws org.wso2.carbon.core.util.CryptoException {

if (SAMPLE_SUBSCRIBER_PASSWORD_1.equals(secret)) {
Expand Down

0 comments on commit 502bd71

Please sign in to comment.