use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testUpdateAPIforStateChange_ToPublishedWithFaultyGWs.
@Test
public void testUpdateAPIforStateChange_ToPublishedWithFaultyGWs() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, APIPersistenceException, XMLStreamException {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
Set<String> environments = new HashSet<String>();
environments.add("Production");
environments.add("Sandbox");
API api = new API(apiId);
api.setContext("/test");
api.setStatus(APIConstants.CREATED);
api.setAsDefaultVersion(true);
api.setEnvironments(environments);
api.setOrganization("carbon.super");
Mockito.when(apimgtDAO.getPublishedDefaultVersion(apiId)).thenReturn("1.0.0");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, null, null);
Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getConfigSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
PublisherAPI publisherAPI = Mockito.mock(PublisherAPI.class);
PowerMockito.when(apiPersistenceInstance.addAPI(any(Organization.class), any(PublisherAPI.class))).thenReturn(publisherAPI);
apiProvider.addAPI(api);
// Mock Updating API
Resource apiSourceArtifact = Mockito.mock(Resource.class);
Mockito.when(apiSourceArtifact.getUUID()).thenReturn("12640983654");
String apiSourcePath = "path";
PowerMockito.when(APIUtil.getAPIPath(api.getId())).thenReturn(apiSourcePath);
PowerMockito.when(apiProvider.registry.get(apiSourcePath)).thenReturn(apiSourceArtifact);
Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_STATUS)).thenReturn("CREATED");
Mockito.when(artifactManager.getGenericArtifact(apiSourceArtifact.getUUID())).thenReturn(artifact);
PowerMockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
Mockito.when(artifact.getId()).thenReturn("12640983654");
PowerMockito.when(GovernanceUtils.getArtifactPath(apiProvider.registry, "12640983654")).thenReturn(apiSourcePath);
Mockito.doNothing().when(artifactManager).updateGenericArtifact(artifact);
try {
apiProvider.updateAPIforStateChange(api, APIConstants.CREATED, APIConstants.PUBLISHED);
} catch (FaultGatewaysException e) {
Assert.assertTrue(e.getFaultMap().contains("Failed to publish"));
}
Assert.assertEquals(2, api.getEnvironments().size());
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetSubscriptionPolicyByUUID.
@Test
public void testGetSubscriptionPolicyByUUID() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
SubscriptionPolicy subscriptionPolicy = Mockito.mock(SubscriptionPolicy.class);
Mockito.when(apimgtDAO.getSubscriptionPolicyByUUID("1111")).thenReturn(subscriptionPolicy, null);
apiProvider.getSubscriptionPolicyByUUID("1111");
try {
assertNotNull(apiProvider.getSubscriptionPolicyByUUID("1111"));
} catch (APIManagementException e) {
assertEquals("Subscription Policy: 1111 was not found.", e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testAddAPI.
@Test
public void testAddAPI() throws Exception {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
API api = new API(apiId);
api.setContext("/test");
api.setStatus(APIConstants.CREATED);
api.setOrganization("carbon.super");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO);
Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
Mockito.when(artifactManager.newGovernanceArtifact(Matchers.any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getConfigSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(apimgtDAO.addAPI(api, -1234, "testOrg")).thenReturn(1);
Mockito.doNothing().when(apimgtDAO).addURITemplates(1, api, -1234);
Mockito.doNothing().when(keyManager).attachResourceScopes(api, api.getUriTemplates());
PublisherAPI publisherAPI = Mockito.mock(PublisherAPI.class);
PowerMockito.when(apiPersistenceInstance.addAPI(any(Organization.class), any(PublisherAPI.class))).thenReturn(publisherAPI);
try {
apiProvider.addAPI(api);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testChangeAPILCCheckListItems.
@Test
public void testChangeAPILCCheckListItems() throws APIManagementException, GovernanceException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
GenericArtifact apiArtifact = Mockito.mock(GenericArtifact.class);
Mockito.when(APIUtil.getAPIArtifact(apiId, apiProvider.registry)).thenReturn(apiArtifact);
Mockito.when(apiArtifact.isLCItemChecked(10, "APILifeCycle")).thenThrow(GovernanceException.class).thenReturn(false, true);
String msg = "Error while setting registry lifecycle checklist items for the API: API1";
try {
apiProvider.changeAPILCCheckListItems(apiId, 10, true);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// status checked
assertTrue(apiProvider.changeAPILCCheckListItems(apiId, 10, true));
// status false
assertTrue(apiProvider.changeAPILCCheckListItems(apiId, 10, true));
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetGlobalPolicyByUUID.
@Test
public void testGetGlobalPolicyByUUID() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
GlobalPolicy globalPolicy = Mockito.mock(GlobalPolicy.class);
Mockito.when(apimgtDAO.getGlobalPolicyByUUID("1111")).thenReturn(globalPolicy, null);
apiProvider.getGlobalPolicyByUUID("1111");
try {
assertNotNull(apiProvider.getGlobalPolicyByUUID("1111"));
} catch (APIManagementException e) {
assertEquals("Global Policy: 1111 was not found.", e.getMessage());
}
}
Aggregations