Skip to content

Commit

Permalink
Adding documentation to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
armstrongmsg committed Dec 19, 2020
1 parent 33ca75d commit 5569285
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 46 deletions.
55 changes: 42 additions & 13 deletions src/test/java/cloud/fogbow/ms/core/ApplicationFacadeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public void setUp() throws FogbowException {
this.facade.setAuthorizationPlugin(authorizationPlugin);
}

// TODO documentation
// test case: When invoking the listMembers method, it
// must call the listMembers method of the MembershipService
// instance it holds and return a list containing the same
// elements.
@Test
public void testListMembers() throws Exception {
this.facade = ApplicationFacade.getInstance();
Expand All @@ -86,9 +89,13 @@ public void testListMembers() throws Exception {
assertEquals(returnedMembersList.size(), 2);
assertTrue(returnedMembersList.contains(member1));
assertTrue(returnedMembersList.contains(member2));

Mockito.verify(this.membershipService, Mockito.times(1)).listMembers();
}

// TODO documentation
// test case: When invoking the addProvider method, it must
// authorize the operation and call the addMember method of
// the MembershipService instance it holds.
@Test
public void testAddProvider() throws FogbowException {
this.facade.addProvider(token, provider);
Expand All @@ -97,15 +104,19 @@ public void testAddProvider() throws FogbowException {
Mockito.verify(membershipService, Mockito.times(1)).addMember(provider);
}

// TODO documentation
// test case: When invoking the addProvider method and
// the operation is not authorized, it must throw an
// UnauthorizedRequestException
@Test(expected = UnauthorizedRequestException.class)
public void testAddProviderUnauthorizedOperation() throws FogbowException {
Mockito.doThrow(new UnauthorizedRequestException()).when(this.authorizationPlugin).isAuthorized(systemUser, operation);

this.facade.addProvider(token, provider);
}

// TODO documentation
// test case: When invoking the removeProvider method, it must
// authorize the operation and call the removeMember method of
// the MembershipService instance it holds.
@Test
public void testRemoveProvider() throws FogbowException {
this.facade.removeProvider(token, provider);
Expand All @@ -114,15 +125,19 @@ public void testRemoveProvider() throws FogbowException {
Mockito.verify(membershipService, Mockito.times(1)).removeMember(provider);
}

// TODO documentation
// test case: When invoking the removeProvider method and
// the operation is not authorized, it must throw an
// UnauthorizedRequestException
@Test(expected = UnauthorizedRequestException.class)
public void testRemoveProviderUnauthorizedOperation() throws FogbowException {
Mockito.doThrow(new UnauthorizedRequestException()).when(this.authorizationPlugin).isAuthorized(systemUser, operation);

this.facade.removeProvider(token, provider);
}

// TODO documentation
// test case: When invoking the addTargetProvider method, it must
// authorize the operation and call the addTarget method of
// the MembershipService instance it holds.
@Test
public void testAddTargetProvider() throws FogbowException {
this.facade.addTargetProvider(token, provider);
Expand All @@ -131,15 +146,19 @@ public void testAddTargetProvider() throws FogbowException {
Mockito.verify(membershipService, Mockito.times(1)).addTarget(provider);
}

// TODO documentation
// test case: When invoking the addTargetProvider method and
// the operation is not authorized, it must throw an
// UnauthorizedRequestException
@Test(expected = UnauthorizedRequestException.class)
public void testAddTargetProviderUnauthorizedOperation() throws FogbowException {
Mockito.doThrow(new UnauthorizedRequestException()).when(this.authorizationPlugin).isAuthorized(systemUser, operation);

this.facade.addTargetProvider(token, provider);
}

// TODO documentation
// test case: When invoking the removeTargetProvider method, it must
// authorize the operation and call the removeTarget method of
// the MembershipService instance it holds.
@Test
public void testRemoveTarget() throws FogbowException {
this.facade.removeTargetProvider(token, provider);
Expand All @@ -148,15 +167,19 @@ public void testRemoveTarget() throws FogbowException {
Mockito.verify(membershipService, Mockito.times(1)).removeTarget(provider);
}

// TODO documentation
// test case: When invoking the removeTargetProvider method and
// the operation is not authorized, it must throw an
// UnauthorizedRequestException
@Test(expected = UnauthorizedRequestException.class)
public void testRemoveTargetProviderUnauthorizedOperation() throws FogbowException {
Mockito.doThrow(new UnauthorizedRequestException()).when(this.authorizationPlugin).isAuthorized(systemUser, operation);

this.facade.removeTargetProvider(token, provider);
}

// TODO documentation
// test case: When invoking the addRequesterProvider method, it must
// authorize the operation and call the addRequester method of
// the MembershipService instance it holds.
@Test
public void testAddRequesterProvider() throws FogbowException {
this.facade.addRequesterProvider(token, provider);
Expand All @@ -165,15 +188,19 @@ public void testAddRequesterProvider() throws FogbowException {
Mockito.verify(membershipService, Mockito.times(1)).addRequester(provider);
}

// TODO documentation
// test case: When invoking the addRequesterProvider method and
// the operation is not authorized, it must throw an
// UnauthorizedRequestException
@Test(expected = UnauthorizedRequestException.class)
public void testAddRequesterProviderUnauthorizedOperation() throws FogbowException {
Mockito.doThrow(new UnauthorizedRequestException()).when(this.authorizationPlugin).isAuthorized(systemUser, operation);

this.facade.addRequesterProvider(token, provider);
}

// TODO documentation
// test case: When invoking the removeRequesterProvider method, it must
// authorize the operation and call the removeRequester method of
// the MembershipService instance it holds.
@Test
public void testRemoveRequesterProvider() throws FogbowException {
this.facade.removeRequesterProvider(token, provider);
Expand All @@ -182,7 +209,9 @@ public void testRemoveRequesterProvider() throws FogbowException {
Mockito.verify(membershipService, Mockito.times(1)).removeRequester(provider);
}

// TODO documentation
// test case: When invoking the removeRequesterProvider method and
// the operation is not authorized, it must throw an
// UnauthorizedRequestException
@Test(expected = UnauthorizedRequestException.class)
public void testRemoveRequesterProviderUnauthorizedOperation() throws FogbowException {
Mockito.doThrow(new UnauthorizedRequestException()).when(this.authorizationPlugin).isAuthorized(systemUser, operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class AdminAuthorizationPluginTest {
private String identityProviderId = "providerId";
private String adminIDsString = String.format("%s,%s", userIdAdmin1, userIdAdmin2);

// TODO add documentation
// test case: When invoking the isAuthorized method with an admin user,
// it must return true
@Test
public void testIsAuthorizedUserIsAdmin() throws UnauthorizedRequestException, ConfigurationErrorException {
setUpConfiguration();
Expand All @@ -46,7 +47,8 @@ public void testIsAuthorizedUserIsAdmin() throws UnauthorizedRequestException, C
assertTrue(plugin.isAuthorized(admin2, operation));
}

// TODO add documentation
// test case: When invoking the isAuthorized method with a non-admin user,
// it must throw an UnauthorizedRequestException
@Test(expected = UnauthorizedRequestException.class)
public void testIsAuthorizedUserIsNotAdmin() throws UnauthorizedRequestException, ConfigurationErrorException {
setUpConfiguration();
Expand All @@ -59,7 +61,9 @@ public void testIsAuthorizedUserIsNotAdmin() throws UnauthorizedRequestException
plugin.isAuthorized(notAdmin, operation);
}

// TODO add documentation
// test case: When attempting to create an instance of
// AdminAuthorizationPlugin using a configuration file
// with no admins listed, it must throw a ConfigurationErrorException
@Test(expected = ConfigurationErrorException.class)
public void testConfigurationMustSetAtLeastOneAdmin() throws ConfigurationErrorException {
String emptyAdminIdsString = "";
Expand Down
51 changes: 36 additions & 15 deletions src/test/java/cloud/fogbow/ms/core/service/AllowListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ public void testIsTargetAuthorizedEmptyNotAllowedRequestersList() throws Configu
Assert.assertFalse(this.service.isRequesterAuthorized(""));
}

// TODO add documentation
// test case: When invoking the addMember method, it must add the given provider correctly,
// so that the change is reflected on the return value of the method listMembers. Also,
// the configuration file must be updated.
@Test
public void testAddMember() throws Exception {
setUpAllowListWithDefaultLists();
Expand Down Expand Up @@ -173,7 +175,9 @@ public void testAddMember() throws Exception {
Assert.assertTrue(updateMembersId.contains(newMember));
}

// TODO add documentation
// test case: When invoking the removeMember method, it must remove the given provider correctly
// from all internal lists, so that the change is reflected on the return value of the methods listMembers,
// isTargetAuthorized and isRequesterAuthorized. Also, the configuration file must be updated.
@Test
public void testRemoveMember() throws Exception {
setUpAllowListWithDefaultLists();
Expand Down Expand Up @@ -219,15 +223,18 @@ public void testRemoveMember() throws Exception {
Assert.assertFalse(this.service.isRequesterAuthorized(memberAuthorizedAsTarget));
}

// TODO add documentation
// test case: When invoking the removeMember method with a provider which is not on
// the memberList, it must throw a ConfigurationErrorException.
@Test(expected = ConfigurationErrorException.class)
public void testRemovingNotKnownMemberMustFail() throws ConfigurationErrorException {
setUpAllowListWithDefaultLists();

this.service.removeMember(notMember1);
}

// TODO add documentation
// test case: When invoking the addTarget method, it must add the given provider
// as target correctly, so that the change is reflected on the return value of the
// method isTargetAuthorized. Also, the configuration file must be updated.
@Test
public void testAddTarget() throws Exception {
setUpAllowListWithTargetListBeforeAdd();
Expand All @@ -251,15 +258,17 @@ public void testAddTarget() throws Exception {
Assert.assertFalse(this.service.isTargetAuthorized(""));
}

// TODO add documentation
// test case: When invoking the addTarget method with a provider which is not on
// the memberList, it must throw a ConfigurationErrorException.
@Test(expected = ConfigurationErrorException.class)
public void testAddingNotKnownTargetMustFail() throws Exception {
setUpAllowListWithTargetListBeforeAdd();

this.service.addTarget(notMember1);
}

// TODO add documentation
// test case: When invoking the addTarget method with a provider which is already
// in the target providers list, it must throw a ConfigurationErrorException.
@Test(expected = ConfigurationErrorException.class)
public void testAddingDuplicateTargetMustFail() throws Exception {
setUpAllowListWithTargetListBeforeAdd();
Expand All @@ -273,7 +282,9 @@ public void testAddingDuplicateTargetMustFail() throws Exception {
this.service.addTarget(memberAuthorizedAsTarget);
}

// TODO add documentation
// test case: When invoking the addRequester method, it must add the given provider
// as requester correctly, so that the change is reflected on the return value of the
// method isRequesterAuthorized. Also, the configuration file must be updated.
@Test
public void testAddRequester() throws ConfigurationErrorException {
setUpAllowListWithRequesterListBeforeAdd();
Expand All @@ -298,15 +309,17 @@ public void testAddRequester() throws ConfigurationErrorException {
Assert.assertFalse(this.service.isRequesterAuthorized(""));
}

// TODO add documentation
// test case: When invoking the addRequester method with a provider which is not on
// the memberList, it must throw a ConfigurationErrorException.
@Test(expected = ConfigurationErrorException.class)
public void testAddingNotKnownRequesterMustFail() throws Exception {
setUpAllowListWithRequesterListBeforeAdd();

this.service.addRequester(notMember1);
}

// TODO add documentation
// test case: When invoking the addRequester method with a provider which is already
// in the requester providers list, it must throw a ConfigurationErrorException.
@Test(expected = ConfigurationErrorException.class)
public void testAddingDuplicateRequesterMustFail() throws Exception {
setUpAllowListWithRequesterListBeforeAdd();
Expand All @@ -320,7 +333,9 @@ public void testAddingDuplicateRequesterMustFail() throws Exception {
this.service.addRequester(memberAuthorizedAsRequester);
}

// TODO add documentation
// test case: When invoking the removeTarget method, it must remove the given provider
// from the targets list correctly, so that the change is reflected on the return value of the
// method isTargetAuthorized. Also, the configuration file must be updated.
@Test
public void testRemoveTarget() throws Exception {
setUpAllowListWithTargetListBeforeRemove();
Expand All @@ -344,23 +359,27 @@ public void testRemoveTarget() throws Exception {
Assert.assertFalse(this.service.isTargetAuthorized(""));
}

// TODO add documentation
// test case: When invoking the removeTarget method with a provider
// which is not a target, it must throw a ConfigurationErrorException.
@Test(expected = ConfigurationErrorException.class)
public void testRemovingUnknownTargetMustFail() throws Exception {
setUpAllowListWithTargetListBeforeRemove();

this.service.removeTarget(memberAuthorizedAsRequester);
}

// TODO add documentation
// test case: When invoking the removeTarget with an unknown provider,
// it must throw a ConfigurationErrorException.
@Test(expected = ConfigurationErrorException.class)
public void testRemovingUnknownProviderFromTargetsMustFail() throws Exception {
setUpAllowListWithTargetListBeforeRemove();

this.service.removeTarget(notMember1);
}

// TODO add documentation
// test case: When invoking the removeRequester method, it must remove the given provider
// from the requesters list correctly, so that the change is reflected on the return value of the
// method isRequesterAuthorized. Also, the configuration file must be updated.
@Test
public void testRemoveRequester() throws Exception {
setUpAllowListWithRequestersListBeforeRemove();
Expand All @@ -384,15 +403,17 @@ public void testRemoveRequester() throws Exception {
Assert.assertFalse(this.service.isRequesterAuthorized(""));
}

// TODO add documentation
// test case: When invoking the removeRequester method with a provider
// which is not a requester, it must throw a ConfigurationErrorException.
@Test(expected = ConfigurationErrorException.class)
public void testRemovingUnknownRequesterMustFail() throws Exception {
setUpAllowListWithRequestersListBeforeRemove();

this.service.removeRequester(memberAuthorizedAsTarget);
}

// TODO add documentation
// test case: When invoking the removeRequester with an unknown provider,
// it must throw a ConfigurationErrorException.
@Test(expected = ConfigurationErrorException.class)
public void testRemovingUnknownProviderFromRequestersMustFail() throws Exception {
setUpAllowListWithRequestersListBeforeRemove();
Expand Down
Loading

0 comments on commit 5569285

Please sign in to comment.