use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetAllProviders.
@Test
public void testGetAllProviders() throws APIManagementException, GovernanceException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
UserRegistry userReg = Mockito.mock(UserRegistry.class);
API api1 = new API(new APIIdentifier("admin", "API1", "1.0.1"));
api1.setContext("api1context");
api1.setStatus(APIConstants.PUBLISHED);
api1.setDescription("API 1 Desciption");
GenericArtifact genericArtifact1 = Mockito.mock(GenericArtifact.class);
GenericArtifact genericArtifact2 = Mockito.mock(GenericArtifact.class);
Mockito.when(genericArtifact1.getAttribute(APIConstants.API_OVERVIEW_NAME)).thenReturn("API1");
Mockito.when(genericArtifact1.getAttribute(APIConstants.API_OVERVIEW_VERSION)).thenReturn("1.0.1");
Mockito.when(genericArtifact1.getAttribute(APIConstants.API_OVERVIEW_CONTEXT)).thenReturn("api1context");
Mockito.when(genericArtifact1.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION)).thenReturn("API 1 Desciption");
Mockito.when(APIUtil.getAPI(genericArtifact1, apiProvider.registry)).thenReturn(api1);
Mockito.when(APIUtil.getAPI(genericArtifact1)).thenReturn(api1);
GenericArtifact[] genericArtifacts = { genericArtifact1, genericArtifact2 };
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(genericArtifacts);
PowerMockito.when(APIUtil.getArtifactManager(userReg, APIConstants.API_KEY)).thenReturn(artifactManager);
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(genericArtifacts);
Assert.assertNotNull(apiProvider.getAllProviders());
// generic artifact null
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(genericArtifacts);
PowerMockito.when(APIUtil.getArtifactManager(userReg, APIConstants.API_KEY)).thenReturn(artifactManager);
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(null);
Assert.assertNotNull(apiProvider.getAllProviders());
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetCustomOutSequences.
@Test
public void testGetCustomOutSequences() throws Exception {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
mockSequences(APIConstants.API_CUSTOM_OUTSEQUENCE_LOCATION, APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT, apiId);
List<String> sequenceList = apiProvider.getCustomOutSequences(apiId);
Assert.assertNotNull(sequenceList);
Assert.assertEquals(2, sequenceList.size());
Assert.assertTrue(sequenceList.contains("fault-seq"));
Assert.assertTrue(sequenceList.contains("custom-fault-seq"));
// OMException when building OMElement
PowerMockito.when(APIUtil.buildOMElement(any(InputStream.class))).thenThrow(new OMException());
apiProvider.getCustomOutSequences(apiId);
// org.wso2.carbon.registry.api.RegistryException
ServiceReferenceHolder sh = PowerMockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(sh);
RegistryService registryService = Mockito.mock(RegistryService.class);
PowerMockito.when(sh.getRegistryService()).thenReturn(registryService);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenReturn(registry);
Mockito.when(registry.resourceExists(APIConstants.API_CUSTOM_OUTSEQUENCE_LOCATION)).thenThrow(org.wso2.carbon.registry.api.RegistryException.class);
String msg = "Issue is in getting custom OutSequences from the Registry";
try {
apiProvider.getCustomOutSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// Registry Exception
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenThrow(RegistryException.class);
try {
apiProvider.getCustomOutSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testAddAPIVersionWithIllegalCharacters.
@Test
public void testAddAPIVersionWithIllegalCharacters() throws APIManagementException, GovernanceException {
APIIdentifier apiId = new APIIdentifier("admin", "API3", "1.0.2&");
API api = new API(apiId);
api.setContext("/test");
api.setStatus(APIConstants.CREATED);
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
try {
apiProvider.addAPI(api);
Assert.fail("Exception was expected, but wasn't thrown");
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains("API Version contains one or more illegal characters"));
}
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testChangeLifeCycleStatus_FaultyGWException.
@Test(expected = FaultGatewaysException.class)
public void testChangeLifeCycleStatus_FaultyGWException() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, WorkflowException, XMLStreamException {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
prepareForChangeLifeCycleStatus(apiProvider, apimgtDAO, apiId, artifact);
GovernanceException exception = new GovernanceException(new APIManagementException("FaultGatewaysException:" + "{\"PUBLISHED\":{\"PROD\":\"Error\"}}"));
Mockito.when(artifact.getLifecycleState()).thenThrow(exception);
apiProvider.changeLifeCycleStatus(apiId, APIConstants.API_LC_ACTION_DEPRECATE, "org1");
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetAPISubscriptionCountByAPI.
@Test
public void testGetAPISubscriptionCountByAPI() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
Long count = Long.parseLong("10");
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
Mockito.when(apimgtDAO.getAPISubscriptionCountByAPI(apiId)).thenReturn(count);
assertEquals(count, (Long) apiProvider.getAPISubscriptionCountByAPI(apiId));
Mockito.when(apimgtDAO.getAPISubscriptionCountByAPI(apiId)).thenThrow(APIManagementException.class);
try {
apiProvider.getAPISubscriptionCountByAPI(apiId);
assertTrue(false);
} catch (APIManagementException e) {
Assert.assertEquals("Failed to get APISubscriptionCount for: API1", e.getMessage());
}
}
Aggregations