Java Code Examples for org.wso2.carbon.apimgt.api.model.API#setVisibility()

The following examples show how to use org.wso2.carbon.apimgt.api.model.API#setVisibility() . 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: 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());

}