use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testChangeLifeCycleStatusAPIMgtException.
@Test(expected = APIManagementException.class)
public void testChangeLifeCycleStatusAPIMgtException() 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("APIManagementException:" + "Error while retrieving Life cycle state"));
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 testCopyAllDocumentation.
@Test
public void testCopyAllDocumentation() throws APIManagementException, RegistryException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
PowerMockito.when(APIUtil.getAPIDocPath(apiId)).thenReturn("oldVersion");
Resource resource = new ResourceImpl();
Mockito.when(apiProvider.registry.get("oldVersion")).thenReturn(resource);
apiProvider.copyAllDocumentation(apiId, "testVersion");
Mockito.verify(apiProvider.registry);
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testUpdateAPI_WithStatusChange.
@Test(expected = APIManagementException.class)
public void testUpdateAPI_WithStatusChange() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, APIPersistenceException, XMLStreamException {
APIIdentifier identifier = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(identifier);
api.setStatus(APIConstants.PUBLISHED);
api.setVisibility("public");
// API status change is not allowed in UpdateAPI(). Should throw an exception.
API oldApi = new API(identifier);
oldApi.setStatus(APIConstants.CREATED);
oldApi.setVisibility("public");
oldApi.setContext("/api1");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, null, null);
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);
Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, oldApi)).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);
PublisherAPI publisherAPI = Mockito.mock(PublisherAPI.class);
PowerMockito.when(apiPersistenceInstance.addAPI(any(Organization.class), any(PublisherAPI.class))).thenReturn(publisherAPI);
apiProvider.addAPI(oldApi);
// mock has permission
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);
// API Status is CREATED and user has permission
Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_STATUS)).thenReturn("CREATED");
Mockito.when(artifactManager.getGenericArtifact(apiSourceArtifact.getUUID())).thenReturn(artifact);
PowerMockito.when(APIUtil.hasPermission(null, APIConstants.Permissions.API_PUBLISH)).thenReturn(true);
PowerMockito.when(APIUtil.hasPermission(null, APIConstants.Permissions.API_CREATE)).thenReturn(true);
apiProvider.updateAPI(api, oldApi);
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetSubscribersOfAPI.
@Test
public void testGetSubscribersOfAPI() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
Set<Subscriber> subscriberSet = new HashSet<Subscriber>();
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
Mockito.when(apimgtDAO.getSubscribersOfAPI(apiId)).thenReturn(subscriberSet);
Assert.assertNotNull(apiProvider.getSubscribersOfAPI(apiId));
Mockito.when(apimgtDAO.getSubscribersOfAPI(apiId)).thenThrow(APIManagementException.class);
try {
apiProvider.getSubscribersOfAPI(apiId);
assertTrue(false);
} catch (APIManagementException e) {
Assert.assertEquals("Failed to get subscribers for API : API1", e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testChangeLifeCycleStatus_WFAlreadyStarted.
@Test
public void testChangeLifeCycleStatus_WFAlreadyStarted() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, WorkflowException {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
GenericArtifact apiArtifact = Mockito.mock(GenericArtifact.class);
Mockito.when(APIUtil.getAPIArtifact(apiId, apiProvider.registry)).thenReturn(apiArtifact);
Mockito.when(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER)).thenReturn("admin");
Mockito.when(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME)).thenReturn("API1");
Mockito.when(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION)).thenReturn("1.0.0");
Mockito.when(apiArtifact.getLifecycleState()).thenReturn("CREATED");
Mockito.when(apimgtDAO.getUUIDFromIdentifier(apiId, "org1")).thenReturn(apiUUID);
Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1);
// Workflow has started already
WorkflowDTO wfDTO = Mockito.mock(WorkflowDTO.class);
Mockito.when(wfDTO.getStatus()).thenReturn(WorkflowStatus.CREATED);
Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference("1", WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(wfDTO);
APIStateChangeResponse response = apiProvider.changeLifeCycleStatus(apiId, APIConstants.API_LC_ACTION_DEPRECATE, "org1");
Assert.assertNotNull(response);
}
Aggregations