Java Code Examples for org.wso2.carbon.registry.core.Resource#setUUID()

The following examples show how to use org.wso2.carbon.registry.core.Resource#setUUID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAllWsdls() throws RegistryException, APIManagementException {
    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();
    Mockito.when(registry.get(resourcePath)).thenThrow(RegistryException.class).thenReturn(resource);
    Mockito.when(registry.resourceExists(wsdlResourcepath)).thenReturn(true);
    try {
        abstractAPIManager.getAllWsdls();
        Assert.fail("Exception not thrown for error scenario");
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("Failed to get wsdl list"));
    }
    resource.setUUID(SAMPLE_RESOURCE_ID);

    List<Wsdl> wsdls = abstractAPIManager.getAllWsdls();
    Assert.assertNotNull(wsdls);
    Assert.assertEquals(wsdls.size(), 1);

}
 
Example 2
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAllGlobalMediationPolicies()
        throws RegistryException, APIManagementException, IOException, XMLStreamException {
    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry);
    Collection parentCollection = new CollectionImpl();
    String mediationResourcePath = APIConstants.API_CUSTOM_SEQUENCE_LOCATION;
    String childCollectionPath = mediationResourcePath + "/testMediation";
    parentCollection.setChildren(new String[] { childCollectionPath });
    Mockito.when(registry.get(mediationResourcePath)).thenReturn(parentCollection);
    Collection childCollection = new CollectionImpl();
    String resourcePath = childCollectionPath + "/policy1";
    childCollection.setChildren(new String[] { resourcePath });
    Mockito.when(registry.get(childCollectionPath)).thenReturn(childCollection);
    Resource resource = new ResourceImpl();
    resource.setUUID(SAMPLE_RESOURCE_ID);

    Mockito.when(registry.get(resourcePath)).thenReturn(resource);
    try {
        abstractAPIManager.getAllGlobalMediationPolicies();
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("Failed to get global mediation policies"));
    }
    String mediationPolicyContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<sequence xmlns=\"http://ws.apache.org/ns/synapse\" name=\"default-endpoint\">\n</sequence>";
    resource.setContent(mediationPolicyContent);

    List<Mediation> policies = abstractAPIManager.getAllGlobalMediationPolicies();
    Assert.assertNotNull(policies);
    Assert.assertEquals(policies.size(), 1);
    PowerMockito.mockStatic(IOUtils.class);
    PowerMockito.mockStatic(AXIOMUtil.class);
    PowerMockito.when(IOUtils.toString((InputStream) Mockito.any(), Mockito.anyString()))
            .thenThrow(IOException.class).thenReturn(mediationPolicyContent);
    PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(XMLStreamException.class);
    abstractAPIManager.getAllGlobalMediationPolicies(); // cover the logged only exceptions
    abstractAPIManager.getAllGlobalMediationPolicies(); // cover the logged only exceptions

}
 
Example 3
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetGlobalMediationPolicy()
        throws RegistryException, APIManagementException, XMLStreamException, IOException {
    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry);
    String resourceUUID = SAMPLE_RESOURCE_ID;
    Collection parentCollection = new CollectionImpl();
    String mediationResourcePath = APIConstants.API_CUSTOM_SEQUENCE_LOCATION;
    String childCollectionPath = mediationResourcePath + "/testMediation";
    parentCollection.setChildren(new String[] { childCollectionPath });
    Mockito.when(registry.get(mediationResourcePath)).thenThrow(RegistryException.class).thenReturn(parentCollection);
    Collection childCollection = new CollectionImpl();
    String resourcePath = childCollectionPath + "/policy1";
    childCollection.setChildren(new String[] { resourcePath });
    Mockito.when(registry.get(childCollectionPath)).thenReturn(childCollection);
    Resource resource = new ResourceImpl(resourcePath, new ResourceDO());
    resource.setUUID(resourceUUID);

    Mockito.when(registry.get(resourcePath)).thenReturn(resource);
    try {
        abstractAPIManager.getGlobalMediationPolicy(resourceUUID);
        Assert.fail("Registry Exception not thrown for error scenario");
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("Error while accessing registry objects"));
    }
    abstractAPIManager.getGlobalMediationPolicy(resourceUUID); // test for registry exception
    String mediationPolicyContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<sequence xmlns=\"http://ws.apache.org/ns/synapse\" name=\"default-endpoint\">\n</sequence>";
    resource.setContent(mediationPolicyContent);
    Mediation policy = abstractAPIManager.getGlobalMediationPolicy(resourceUUID);
    Assert.assertNotNull(policy);
    PowerMockito.mockStatic(IOUtils.class);
    PowerMockito.mockStatic(AXIOMUtil.class);
    PowerMockito.when(IOUtils.toString((InputStream) Mockito.any(), Mockito.anyString()))
            .thenThrow(IOException.class).thenReturn(mediationPolicyContent);
    PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(XMLStreamException.class);
    abstractAPIManager.getGlobalMediationPolicy(resourceUUID); // cover the logged only exceptions
    abstractAPIManager.getGlobalMediationPolicy(resourceUUID); // cover the logged only exceptions

}
 
Example 4
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetWsdlById() throws RegistryException, APIManagementException, IOException {
    String resourceId = SAMPLE_RESOURCE_ID;
    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(false, true);
    Assert.assertNull(abstractAPIManager.getWsdlById(resourceId));
    resource.setUUID(resourceId);
    try {
        abstractAPIManager.getWsdlById(resourceId);
        Assert.fail("Exception not thrown for error scenario");
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("Error while accessing registry objects"));
    }
    String wsdlContent = "sample wsdl";
    resource.setContent(wsdlContent);
    Wsdl wsdl = abstractAPIManager.getWsdlById(resourceId);
    Assert.assertNotNull(wsdl);
    PowerMockito.mockStatic(IOUtils.class);
    PowerMockito.when(IOUtils.toString((InputStream) Mockito.any(), Mockito.anyString()))
            .thenThrow(IOException.class);
    abstractAPIManager.getWsdlById(resourceId);// covers logged only exception;

}
 
Example 5
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDocumentation() throws APIManagementException, RegistryException {
    Registry registry = Mockito.mock(UserRegistry.class);
    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(genericArtifactManager, registry, null);
    APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION);
    String documentationName = "doc1";
    String contentPath = APIConstants.API_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName()
            + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR
            + identifier.getVersion() + RegistryConstants.PATH_SEPARATOR + APIConstants.DOC_DIR
            + RegistryConstants.PATH_SEPARATOR + documentationName;
    GenericArtifact genericArtifact = getGenericArtifact(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION,
            "sample");
    String docType = "other";
    genericArtifact.setAttribute(APIConstants.DOC_TYPE, docType);
    genericArtifact.setAttribute(APIConstants.DOC_SOURCE_TYPE, "URL");
    Resource resource = new ResourceImpl();
    resource.setUUID(SAMPLE_RESOURCE_ID);
    Mockito.when(registry.get(contentPath)).thenThrow(RegistryException.class).thenReturn(resource);
    Mockito.when(genericArtifactManager.getGenericArtifact(SAMPLE_RESOURCE_ID)).thenReturn(genericArtifact);
    try {
        abstractAPIManager.getDocumentation(identifier, DocumentationType.OTHER, documentationName);
        Assert.fail("Registry exception not thrown for error scenario");
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("Failed to get documentation details"));
    }
    Assert.assertTrue(
            abstractAPIManager.getDocumentation(identifier, DocumentationType.OTHER, documentationName).getId()
                    .equals(genericArtifact.getId()));
}
 
Example 6
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSubscriberAPIs() throws APIManagementException, RegistryException {
    Subscriber subscriber = new Subscriber("sub1");
    Application application = new Application("app1", subscriber);
    application.setId(1);
    SubscribedAPI subscribedAPI1 = new SubscribedAPI(subscriber,
            getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION));
    subscribedAPI1.setUUID(SAMPLE_RESOURCE_ID);
    SubscribedAPI subscribedAPI2 = new SubscribedAPI(subscriber, getAPIIdentifier("sample1", API_PROVIDER, "2.0.0"));
    Set<SubscribedAPI> subscribedAPIs = new HashSet<SubscribedAPI>();
    subscribedAPI1.setApplication(application);
    subscribedAPI2.setApplication(application);
    subscribedAPIs.add(subscribedAPI1);
    subscribedAPIs.add(subscribedAPI2);
    Mockito.when(apiMgtDAO.getSubscribedAPIs((Subscriber) Mockito.any(), Mockito.anyString()))
            .thenReturn(subscribedAPIs);
    UserRegistry registry = Mockito.mock(UserRegistry.class);
    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(genericArtifactManager, null, registry,
            null, apiMgtDAO);
    Resource resource = new ResourceImpl();
    resource.setUUID(SAMPLE_RESOURCE_ID);
    Mockito.when(registry.get(Mockito.anyString())).thenThrow(RegistryException.class).thenReturn(resource);
    try {
        abstractAPIManager.getSubscriberAPIs(subscriber);
        Assert.fail("Registry exception not thrown for error scenario");
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("Failed to get APIs for subscriber: "));
    }
    GenericArtifact artifact = getGenericArtifact(SAMPLE_API_NAME,API_PROVIDER,SAMPLE_API_VERSION,"sample_qname");
    Mockito.when(genericArtifactManager.getGenericArtifact(Mockito.anyString())).thenReturn(artifact);
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.when(APIUtil.getAPI((GovernanceArtifact)Mockito.any(),(Registry)Mockito.any())).thenReturn(new API
            (getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION)));
    abstractAPIManager.tenantDomain = SAMPLE_TENANT_DOMAIN_1;
    Assert.assertEquals(abstractAPIManager.getSubscriberAPIs(subscriber).size(),1);

}
 
Example 7
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCreatedResourceUuid() throws RegistryException, APIManagementException {
    Resource resource = new ResourceImpl();
    resource.setUUID(SAMPLE_RESOURCE_ID);
    Mockito.when(registry.get(Mockito.anyString())).thenThrow(RegistryException.class).thenReturn(resource);
    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry);
    Assert.assertNull(abstractAPIManager.getCreatedResourceUuid("/test/path"));
    Assert.assertEquals(abstractAPIManager.getCreatedResourceUuid("/test/path"), SAMPLE_RESOURCE_ID);
}
 
Example 8
Source File: APIConsumerImplTest.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetPublishedAPIsByProvider1()
        throws APIManagementException, RegistryException, org.wso2.carbon.user.core.UserStoreException {
    APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
    String providerId = "1";
    API api = new API(new APIIdentifier(API_PROVIDER, SAMPLE_API_NAME, SAMPLE_API_VERSION));
    API api1 = new API(new APIIdentifier(API_PROVIDER, "pizza_api", "2.0.0"));
    PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(true, false);
    PowerMockito.when(APIUtil.isAllowDisplayAPIsWithMultipleStatus()).thenReturn(true, false);
    PowerMockito.when(APIUtil.getArtifactManager(userRegistry, APIConstants.API_KEY))
            .thenReturn(genericArtifactManager);
    PowerMockito.when(APIUtil.getMountedPath(Mockito.any(), Mockito.anyString())).thenReturn("system/governance");
    PowerMockito.when(APIUtil.getAPI(Mockito.any())).thenReturn(api);
    PowerMockito.when(APIUtil.replaceEmailDomainBack(Mockito.anyString())).thenReturn(providerId);
    PowerMockito.when(APIUtil.getLcStateFromArtifact((GovernanceArtifact) Mockito.any()))
            .thenReturn(APIConstants.PUBLISHED);
    GenericArtifact genericArtifact1 = new GenericArtifactImpl(new QName("local"), "artifact1");
    GenericArtifact genericArtifact2 = new GenericArtifactImpl(new QName("local"), "artifact2");
    GenericArtifact[] genericArtifacts = new GenericArtifact[] { genericArtifact1, genericArtifact2 };
    Mockito.when(genericArtifactManager.findGenericArtifacts((Map<String, List<String>>) Mockito.any()))
            .thenThrow(GovernanceException.class).thenReturn(genericArtifacts);
    PowerMockito.mockStatic(GovernanceUtils.class);
    PowerMockito.when(GovernanceUtils.getArtifactPath(Mockito.any(), Mockito.anyString())).thenReturn("/path1");
    PowerMockito.when(RegistryUtils.getAbsolutePath(Mockito.any(), Mockito.anyString())).thenReturn("/path1");
    Assert.assertNull(apiConsumer.getPublishedAPIsByProvider("1", "test_user", 5, API_PROVIDER, "John"));
    Assert.assertEquals(0,
            apiConsumer.getPublishedAPIsByProvider("1", "test_user", 5, API_PROVIDER, "John").size());
    Mockito.when(
            authorizationManager.isUserAuthorized(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
            .thenReturn(true);
    Resource resource = new ResourceImpl();
    resource.setUUID(UUID.randomUUID().toString());
    Mockito.when(userRegistry.get(Mockito.anyString())).thenReturn(resource);
    GenericArtifact genericArtifact = Mockito.mock(GenericArtifactImpl.class);
    Mockito.when(genericArtifactManager.getGenericArtifact(Mockito.anyString())).thenReturn(genericArtifact);
    Assert.assertEquals(1,
            apiConsumer.getPublishedAPIsByProvider("1", "test_user", 1, API_PROVIDER, "John").size());
    api.setVisibility("specific_to_roles");
    PowerMockito.when(MultitenantUtils.getTenantDomain(Mockito.anyString()))
            .thenReturn("carbon.super", "carbon.super", SAMPLE_TENANT_DOMAIN_1);
    PowerMockito.when(APIUtil.getAPI((GenericArtifact) Mockito.any())).thenReturn(api, api1);
    Assert.assertEquals(1,
            apiConsumer.getPublishedAPIsByProvider("1", "test_user", 5, API_PROVIDER, "John").size());
    Mockito.when(
            authorizationManager.isRoleAuthorized(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
            .thenReturn(true);
    Assert.assertEquals(1, apiConsumer.getPublishedAPIsByProvider("1", "", 5, API_PROVIDER, "John").size());

}
 
Example 9
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetAllDocumentation() throws APIManagementException, RegistryException {
    Registry registry = Mockito.mock(UserRegistry.class);

    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(genericArtifactManager, registry, null);
    abstractAPIManager.registry = registry;

    GenericArtifact genericArtifact = getGenericArtifact(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION,
            "sample");
    genericArtifact.setAttribute(APIConstants.DOC_TYPE, "Other");
    genericArtifact.setAttribute(APIConstants.DOC_SOURCE_TYPE, "URL");
    Association association = new Association();
    String associationDestinationPath = "doc/destination";
    association.setDestinationPath(associationDestinationPath);
    Association[] associations = new Association[] { association };
    APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION);
    String apiResourcePath =
            APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName()
                    + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR
                    + identifier.getVersion() + APIConstants.API_RESOURCE_NAME;
    Mockito.when(registry.getAssociations(apiResourcePath, APIConstants.DOCUMENTATION_ASSOCIATION))
            .thenThrow(RegistryException.class).thenReturn(associations);
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.when(APIUtil.getAPIPath(identifier)).thenReturn(apiResourcePath);

    Mockito.when(genericArtifact.getPath()).thenReturn("test");
    String docName = "sample";
    Documentation documentation = new Documentation(DocumentationType.HOWTO, docName);
    PowerMockito.when(APIUtil.getDocumentation(genericArtifact)).thenReturn(documentation);
    try {
        abstractAPIManager.getAllDocumentation(identifier);
        Assert.fail("Registry exception not thrown for error scenario");
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("Failed to get documentations for api"));
    }

    Resource resource = new ResourceImpl();
    resource.setUUID(SAMPLE_RESOURCE_ID);
    Mockito.when(registry.get(associationDestinationPath)).thenReturn(resource);
    Mockito.when(genericArtifactManager.getGenericArtifact(SAMPLE_RESOURCE_ID)).thenReturn(genericArtifact);
    List<Documentation> documentationList = abstractAPIManager.getAllDocumentation(identifier);
    Assert.assertNotNull(documentationList);
    Assert.assertEquals(documentationList.size(), 1);
    String documentationName = "doc1";
    String contentPath = APIConstants.API_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName()
            + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR
            + identifier.getVersion() + RegistryConstants.PATH_SEPARATOR + APIConstants.DOC_DIR
            + RegistryConstants.PATH_SEPARATOR + RegistryConstants.PATH_SEPARATOR + documentationName;
    genericArtifact.setAttribute(APIConstants.DOC_SOURCE_TYPE, "In line");
    genericArtifact.setAttribute(APIConstants.DOC_NAME, documentationName);
    ResourceDO resourceDO = new ResourceDO();
    resourceDO.setLastUpdatedOn(12344567);
    Resource resource1 = new ResourceImpl(contentPath, resourceDO);
    Mockito.when(registry.get(contentPath)).thenReturn(resource1);
    documentationList = abstractAPIManager.getAllDocumentation(identifier);
    Assert.assertNotNull(documentationList);
    Assert.assertEquals(documentationList.size(), 1);

}
 
Example 10
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetAllApiSpecificMediationPolicies()
        throws RegistryException, APIManagementException, IOException, XMLStreamException {
    APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION);
    String parentCollectionPath =
            APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName()
                    + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR
                    + identifier.getVersion() + APIConstants.API_RESOURCE_NAME;
    parentCollectionPath = parentCollectionPath.substring(0, parentCollectionPath.lastIndexOf("/"));
    Collection parentCollection = new CollectionImpl();
    parentCollection.setChildren(new String[] {
            parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN,
            parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT,
            parentCollectionPath + RegistryConstants.PATH_SEPARATOR
                    + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT });
    Collection childCollection = new CollectionImpl();
    childCollection.setChildren(new String[] { "mediation1" });
    Mockito.when(registry.get(parentCollectionPath)).thenThrow(RegistryException.class)
            .thenReturn(parentCollection);
    Mockito.when(registry.get(
            parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN))
            .thenReturn(childCollection);

    Resource resource = new ResourceImpl();
    resource.setUUID(SAMPLE_RESOURCE_ID);

    String mediationPolicyContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<sequence xmlns=\"http://ws.apache.org/ns/synapse\" name=\"default-endpoint\">\n</sequence>";
    resource.setContent(mediationPolicyContent);
    Mockito.when(registry.get("mediation1")).thenReturn(resource);
    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry);
    try {
        abstractAPIManager.getAllApiSpecificMediationPolicies(identifier);
        Assert.fail("Registry exception not thrown for error scenario");
    } catch (APIManagementException e) {
        Assert.assertTrue(
                e.getMessage().contains("Error occurred  while getting Api Specific mediation policies "));
    }
    Assert.assertEquals(abstractAPIManager.getAllApiSpecificMediationPolicies(identifier).size(), 1);
    PowerMockito.mockStatic(IOUtils.class);
    PowerMockito.mockStatic(AXIOMUtil.class);
    PowerMockito.when(IOUtils.toString((InputStream) Mockito.any(), Mockito.anyString()))
            .thenThrow(IOException.class).thenReturn(mediationPolicyContent);
    PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(XMLStreamException.class);
    abstractAPIManager.getAllApiSpecificMediationPolicies(identifier);// covers exception which is only logged
    abstractAPIManager.getAllApiSpecificMediationPolicies(identifier);// covers exception which is only logged
}