use of org.wso2.carbon.apimgt.api.model.DuplicateAPIException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testCreateNewAPIVersion_Exception.
@Test(expected = APIManagementException.class)
public void testCreateNewAPIVersion_Exception() throws RegistryException, UserStoreException, APIManagementException, IOException, DuplicateAPIException, APIPersistenceException, XMLStreamException {
// Create Original API
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId);
api.setContext("/test");
api.setVisibility("Public");
api.setStatus(APIConstants.CREATED);
String newVersion = "1.0.0";
// Create new API object
APIIdentifier newApiId = new APIIdentifier("admin", "API1", "1.0.1");
final API newApi = new API(newApiId);
newApi.setStatus(APIConstants.CREATED);
newApi.setContext("/test");
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);
GenericArtifact artifactNew = Mockito.mock(GenericArtifact.class);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, newApi)).thenReturn(artifactNew);
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);
String targetPath = APIConstants.API_LOCATION + RegistryConstants.PATH_SEPARATOR + api.getId().getProviderName() + RegistryConstants.PATH_SEPARATOR + api.getId().getApiName() + RegistryConstants.PATH_SEPARATOR + newVersion + APIConstants.API_RESOURCE_NAME;
String apiSourcePath = "API1/1.0.0/";
PowerMockito.when(APIUtil.getAPIPath(apiId)).thenReturn(apiSourcePath);
Mockito.when(apiProvider.registry.resourceExists(targetPath)).thenThrow(RegistryException.class);
apiProvider.createNewAPIVersion(api.getUuid(), newVersion, false, "carbon.super");
}
use of org.wso2.carbon.apimgt.api.model.DuplicateAPIException in project carbon-apimgt by wso2.
the class RestApiUtilTest method testisDueToResourceAlreadyExistsWithDuplicateAPIException.
@Test
public void testisDueToResourceAlreadyExistsWithDuplicateAPIException() throws Exception {
DuplicateAPIException duplicateAPIException = new DuplicateAPIException("New Sample exception");
Throwable testThrowable = new Throwable();
PowerMockito.spy(RestApiUtil.class);
PowerMockito.doReturn(duplicateAPIException).when(RestApiUtil.class, "getPossibleErrorCause", testThrowable);
Assert.assertTrue("Invalid exception has been passed.", RestApiUtil.isDueToResourceAlreadyExists(testThrowable));
}
Aggregations