diff --git a/src/test/java/cloud/fogbow/ms/core/ApplicationFacadeTest.java b/src/test/java/cloud/fogbow/ms/core/ApplicationFacadeTest.java index cbaa491..576eaad 100644 --- a/src/test/java/cloud/fogbow/ms/core/ApplicationFacadeTest.java +++ b/src/test/java/cloud/fogbow/ms/core/ApplicationFacadeTest.java @@ -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(); @@ -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); @@ -97,7 +104,9 @@ 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); @@ -105,7 +114,9 @@ public void testAddProviderUnauthorizedOperation() throws FogbowException { 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); @@ -114,7 +125,9 @@ 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); @@ -122,7 +135,9 @@ public void testRemoveProviderUnauthorizedOperation() throws FogbowException { 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); @@ -131,7 +146,9 @@ 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); @@ -139,7 +156,9 @@ public void testAddTargetProviderUnauthorizedOperation() throws FogbowException 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); @@ -148,7 +167,9 @@ 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); @@ -156,7 +177,9 @@ public void testRemoveTargetProviderUnauthorizedOperation() throws FogbowExcepti 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); @@ -165,7 +188,9 @@ 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); @@ -173,7 +198,9 @@ public void testAddRequesterProviderUnauthorizedOperation() throws FogbowExcepti 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); @@ -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); diff --git a/src/test/java/cloud/fogbow/ms/core/authorization/AdminAuthorizationPluginTest.java b/src/test/java/cloud/fogbow/ms/core/authorization/AdminAuthorizationPluginTest.java index 7833903..92262de 100644 --- a/src/test/java/cloud/fogbow/ms/core/authorization/AdminAuthorizationPluginTest.java +++ b/src/test/java/cloud/fogbow/ms/core/authorization/AdminAuthorizationPluginTest.java @@ -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(); @@ -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(); @@ -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 = ""; diff --git a/src/test/java/cloud/fogbow/ms/core/service/AllowListTest.java b/src/test/java/cloud/fogbow/ms/core/service/AllowListTest.java index 6f645df..3f6b4c4 100644 --- a/src/test/java/cloud/fogbow/ms/core/service/AllowListTest.java +++ b/src/test/java/cloud/fogbow/ms/core/service/AllowListTest.java @@ -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(); @@ -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(); @@ -219,7 +223,8 @@ 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(); @@ -227,7 +232,9 @@ public void testRemovingNotKnownMemberMustFail() throws ConfigurationErrorExcept 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(); @@ -251,7 +258,8 @@ 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(); @@ -259,7 +267,8 @@ public void testAddingNotKnownTargetMustFail() throws Exception { 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(); @@ -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(); @@ -298,7 +309,8 @@ 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(); @@ -306,7 +318,8 @@ public void testAddingNotKnownRequesterMustFail() throws Exception { 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(); @@ -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(); @@ -344,7 +359,8 @@ 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(); @@ -352,7 +368,8 @@ public void testRemovingUnknownTargetMustFail() throws Exception { 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(); @@ -360,7 +377,9 @@ public void testRemovingUnknownProviderFromTargetsMustFail() throws Exception { 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(); @@ -384,7 +403,8 @@ 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(); @@ -392,7 +412,8 @@ public void testRemovingUnknownRequesterMustFail() throws Exception { 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(); diff --git a/src/test/java/cloud/fogbow/ms/core/service/BlockListTest.java b/src/test/java/cloud/fogbow/ms/core/service/BlockListTest.java index 6ee1fd0..3e88b16 100644 --- a/src/test/java/cloud/fogbow/ms/core/service/BlockListTest.java +++ b/src/test/java/cloud/fogbow/ms/core/service/BlockListTest.java @@ -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 { setUpBlockListWithDefaultLists(); @@ -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 { setUpBlockListWithDefaultLists(); @@ -219,7 +223,8 @@ public void testRemoveMember() throws Exception { Assert.assertTrue(this.service.isRequesterAuthorized(memberNotAuthorizedAsTarget)); } - // 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 { setUpBlockListWithDefaultLists(); @@ -227,7 +232,9 @@ public void testRemovingNotKnownMemberMustFail() throws ConfigurationErrorExcept 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 { setUpBlockListWithTargetListBeforeAdd(); @@ -251,7 +258,8 @@ 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 testAddNotKnownTargetMustFail() throws Exception { setUpBlockListWithTargetListBeforeAdd(); @@ -259,7 +267,8 @@ public void testAddNotKnownTargetMustFail() throws Exception { 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 { setUpBlockListWithTargetListBeforeAdd(); @@ -273,7 +282,9 @@ public void testAddingDuplicateTargetMustFail() throws Exception { this.service.addTarget(memberNotAuthorizedAsTarget); } - // 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 { setUpBlockListWithRequesterListBeforeAdd(); @@ -297,7 +308,8 @@ 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 { setUpBlockListWithRequesterListBeforeAdd(); @@ -305,7 +317,8 @@ public void testAddingNotKnownRequesterMustFail() throws Exception { 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 { setUpBlockListWithRequesterListBeforeAdd(); @@ -319,7 +332,9 @@ public void testAddingDuplicateRequesterMustFail() throws Exception { this.service.addRequester(memberNotAuthorizedAsRequester); } - // 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 { setUpBlockListWithTargetListBeforeRemove(); @@ -343,7 +358,8 @@ 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 { setUpBlockListWithTargetListBeforeRemove(); @@ -351,7 +367,8 @@ public void testRemovingUnknownTargetMustFail() throws Exception { this.service.removeTarget(memberNotAuthorizedAsRequester); } - // 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 { setUpBlockListWithTargetListBeforeRemove(); @@ -359,7 +376,9 @@ public void testRemovingUnknownProviderFromTargetsMustFail() throws Exception { 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 { setUpBlockListWithRequestersListBeforeRemove(); @@ -383,7 +402,8 @@ 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 { setUpBlockListWithRequestersListBeforeRemove(); @@ -391,7 +411,8 @@ public void testRemovingUnknownRequesterMustFail() throws Exception { this.service.removeRequester(memberNotAuthorizedAsTarget); } - // 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 { setUpBlockListWithRequestersListBeforeRemove();