use of org.wso2.carbon.registry.core.CollectionImpl in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testDeleteWsdl.
@Test
public void testDeleteWsdl() throws APIManagementException, RegistryException {
AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry);
Collection parentCollection = new CollectionImpl();
String wsdlResourcePath = APIConstants.API_WSDL_RESOURCE;
String resourcePath = wsdlResourcePath + "/wsdl1";
parentCollection.setChildren(new String[] { resourcePath });
Mockito.when(registry.get(wsdlResourcePath)).thenReturn(parentCollection);
Resource resource = new ResourceImpl(resourcePath, new ResourceDO());
Mockito.when(registry.get(resourcePath)).thenThrow(RegistryException.class).thenReturn(resource);
Mockito.when(registry.resourceExists(wsdlResourcePath)).thenReturn(true);
try {
abstractAPIManager.deleteWsdl(SAMPLE_RESOURCE_ID);
Assert.fail("Exception not thrown for error scenario");
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains("Error while accessing registry objects"));
}
Mockito.when(registry.resourceExists(resourcePath)).thenReturn(true, true, true, true, false);
resource.setUUID(SAMPLE_RESOURCE_ID);
Mockito.doThrow(RegistryException.class).doNothing().when(registry).delete(resourcePath);
try {
abstractAPIManager.deleteWsdl(SAMPLE_RESOURCE_ID);
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains("Failed to delete wsdl"));
}
Assert.assertFalse(abstractAPIManager.deleteWsdl(SAMPLE_RESOURCE_ID));
Assert.assertTrue(abstractAPIManager.deleteWsdl(SAMPLE_RESOURCE_ID));
}
Aggregations