use of org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy in project carbon-apimgt by wso2.
the class ApplicationMappingUtilTestCase method testFromApplicationToDTO.
@Test
public void testFromApplicationToDTO() {
String applicationID = UUID.randomUUID().toString();
Application application1 = new Application("application1", "user1");
application1.setId(applicationID);
application1.setDescription("application 1");
application1.setStatus("ACTIVE");
application1.setPolicy(new APIPolicy("GOLD"));
ApplicationMappingUtil applicationMappingUtil = new ApplicationMappingUtil();
ApplicationDTO applicationDTO = applicationMappingUtil.fromApplicationToDTO(application1);
Assert.assertEquals(applicationDTO.getApplicationId(), applicationID);
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy in project carbon-apimgt by wso2.
the class ApplicationMappingUtilTestCase method testFromApplicationsToDTO.
@Test
public void testFromApplicationsToDTO() {
Application application1 = new Application("application1", "user1");
application1.setId(UUID.randomUUID().toString());
application1.setDescription("application 1");
application1.setStatus("ACTIVE");
application1.setPolicy(new APIPolicy("GOLD"));
Application application2 = new Application("application2", "user1");
application2.setId(UUID.randomUUID().toString());
application2.setDescription("application 2");
application2.setStatus("ACTIVE");
application2.setPolicy(new APIPolicy("GOLD"));
Application application3 = new Application("application3", "user1");
application3.setId(UUID.randomUUID().toString());
application3.setDescription("application 3");
application3.setStatus("ACTIVE");
application3.setPolicy(new APIPolicy("GOLD"));
List<Application> applicationList = new ArrayList<>();
applicationList.add(application1);
applicationList.add(application2);
applicationList.add(application3);
ApplicationMappingUtil applicationMappingUtil = new ApplicationMappingUtil();
ApplicationListDTO applicationListDTO = applicationMappingUtil.fromApplicationsToDTO(applicationList, 10, 0);
Assert.assertEquals(applicationListDTO.getList().get(0).getName(), "application1");
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeletePolicyByUuid.
@Test(description = "Test delete policy by UUID")
public void testDeletePolicyByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
adminService.deletePolicyByUuid(apiPolicy.getUuid(), APIMgtAdminService.PolicyLevel.api);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).deletePolicyByUuid(APIMgtAdminService.PolicyLevel.api, apiPolicy.getUuid());
try {
adminService.deletePolicyByUuid(apiPolicy.getUuid(), APIMgtAdminService.PolicyLevel.api);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't delete policy with id: " + apiPolicy.getUuid() + ", level: " + APIMgtAdminService.PolicyLevel.api);
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIWithRestrictedVisibilityButDifferentContext.
@Test(description = "Test UpdateAPI with restricted visibility but different context")
public void testUpdateAPIWithRestrictedVisibilityButDifferentContext() throws APIManagementException {
Set<String> visibleRoles = new HashSet<>();
visibleRoles.add(ADMIN_ROLE);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI().visibility(API.Visibility.RESTRICTED).visibleRoles(visibleRoles);
String uuid = api.getId();
APIGateway gateway = Mockito.mock(APIGateway.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.build());
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
Mockito.when(identityProvider.getRoleId(ADMIN_ROLE)).thenReturn(ADMIN_ROLE_ID);
Mockito.when(identityProvider.getRoleId(DEVELOPER_ROLE)).thenReturn(DEVELOPER_ROLE_ID);
apiPublisher.updateAPI(api.context("testContext"));
Mockito.verify(apiDAO, Mockito.times(1)).getAPI(uuid);
Mockito.verify(apiDAO, Mockito.times(1)).isAPIContextExists(api.getContext());
Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(uuid, api.build());
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddPolicy.
@Test(description = "Add policy")
public void testAddPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicy();
adminService.addApiPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addApiPolicy(policy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addApiPolicy(policy);
try {
adminService.addApiPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add API policy for uuid: " + policy.getUuid());
}
}
Aggregations