Search in sources :

Example 11 with CollectionImpl

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));
}
Also used : ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) CollectionImpl(org.wso2.carbon.registry.core.CollectionImpl) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ResourceDO(org.wso2.carbon.registry.core.jdbc.dataobjects.ResourceDO) Resource(org.wso2.carbon.registry.core.Resource) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CollectionImpl (org.wso2.carbon.registry.core.CollectionImpl)11 Resource (org.wso2.carbon.registry.core.Resource)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 Test (org.junit.Test)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Collection (org.wso2.carbon.registry.core.Collection)9 ResourceImpl (org.wso2.carbon.registry.core.ResourceImpl)9 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)9 ResourceDO (org.wso2.carbon.registry.core.jdbc.dataobjects.ResourceDO)6 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ArrayInputStream (org.apache.derby.iapi.services.io.ArrayInputStream)4 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)4 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)4 Registry (org.wso2.carbon.registry.core.Registry)3 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)2 Documentation (org.wso2.carbon.apimgt.api.model.Documentation)2 Mediation (org.wso2.carbon.apimgt.api.model.Mediation)2 Wsdl (org.wso2.carbon.apimgt.api.model.Wsdl)2