use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifactImpl in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method getGenericArtifact.
private GenericArtifact getGenericArtifact(String apiName, String provider, String version, String qName) throws GovernanceException {
String id = UUID.randomUUID().toString();
GenericArtifact genericArtifact = new GenericArtifactImpl(id, new QName(qName), "");
genericArtifact.setAttribute(APIConstants.API_OVERVIEW_PROVIDER, provider);
genericArtifact.setAttribute(APIConstants.API_OVERVIEW_NAME, apiName);
genericArtifact.setAttribute(APIConstants.API_OVERVIEW_VERSION, version);
return genericArtifact;
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifactImpl in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetPaginatedAPIsWithTag.
@Test
public void testGetPaginatedAPIsWithTag() throws Exception {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.mockStatic(GovernanceUtils.class);
GovernanceArtifact governanceArtifact = new GenericArtifactImpl(UUID.randomUUID().toString(), new QName(UUID.randomUUID().toString(), "UUID.randomUUID().toString()"), "api");
List<GovernanceArtifact> governanceArtifactList = new ArrayList();
governanceArtifactList.add(governanceArtifact);
Mockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyString(), (Registry) Mockito.anyObject(), Mockito.anyString())).thenReturn(governanceArtifactList);
assertNotNull(apiConsumer.getPaginatedAPIsWithTag("testTag", 0, 10, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifactImpl in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetPublishedAPIsByProvider1.
@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());
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifactImpl in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetPublishedAPIsByProvider2.
@Test
public void testGetPublishedAPIsByProvider2() throws APIManagementException, RegistryException, org.wso2.carbon.user.core.UserStoreException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
String providerId = "2";
API api = new API(new APIIdentifier(API_PROVIDER, SAMPLE_API_NAME, SAMPLE_API_VERSION));
API api1 = new API(new APIIdentifier(API_PROVIDER, SAMPLE_API_NAME, "2.0.0"));
PowerMockito.mockStatic(APIUtil.class);
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())).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");
Association association = new Association();
association.setDestinationPath("/destPath1");
Association association2 = new Association();
association2.setDestinationPath("/destPath2");
Association[] associations = new Association[] { association, association2 };
Mockito.when(userRegistry.getAssociations(Mockito.anyString(), Mockito.anyString())).thenThrow(RegistryException.class).thenReturn(associations);
try {
apiConsumer.getPublishedAPIsByProvider("1", "test_user", 5, API_PROVIDER, "");
Assert.fail("Registry exception not thrown for error scenario");
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains("Failed to get Published APIs for provider :"));
}
Assert.assertEquals(0, apiConsumer.getPublishedAPIsByProvider("1", "test_user", 2, API_PROVIDER, "").size());
Mockito.when(authorizationManager.isUserAuthorized(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenThrow(UserStoreException.class).thenThrow(org.wso2.carbon.user.core.UserStoreException.class).thenReturn(true);
try {
apiConsumer.getPublishedAPIsByProvider("1", "test_user", 5, API_PROVIDER, "");
Assert.fail("User store exception not thrown for error scenario");
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains("Failed to get Published APIs for provider :"));
}
try {
apiConsumer.getPublishedAPIsByProvider("1", "test_user", 5, API_PROVIDER, "");
Assert.fail("User store exception not thrown for error scenario");
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains("Failed to get Published APIs for provider :"));
}
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(genericArtifact.getLifecycleState(Mockito.anyString())).thenReturn(APIConstants.PUBLISHED);
Mockito.when(genericArtifactManager.getGenericArtifact(Mockito.anyString())).thenReturn(genericArtifact);
Assert.assertEquals(1, apiConsumer.getPublishedAPIsByProvider("1", "test_user", 1, API_PROVIDER, "").size());
PowerMockito.when(APIUtil.getAPI((GenericArtifact) Mockito.any())).thenReturn(api, api1);
Assert.assertEquals(1, apiConsumer.getPublishedAPIsByProvider("1", "test_user", 5, API_PROVIDER, "").size());
PowerMockito.when(APIUtil.isAllowDisplayAPIsWithMultipleStatus()).thenReturn(true);
Set<API> apiSet = apiConsumer.getPublishedAPIsByProvider("1", "test_user", 5, API_PROVIDER, "");
Assert.assertEquals(1, apiSet.size());
Assert.assertTrue(apiSet.contains(api1));
String apiOwner = "Smith";
PowerMockito.when(APIUtil.replaceEmailDomainBack(apiOwner)).thenReturn(apiOwner);
api.setApiOwner("John");
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(true);
Assert.assertEquals(1, apiConsumer.getPublishedAPIsByProvider(apiOwner, "test_user", 1, apiOwner, "").size());
Assert.assertEquals(0, apiConsumer.getPublishedAPIsByProvider("1", "test_user", 1, apiOwner, "").size());
}
Aggregations