use of org.wso2.carbon.apimgt.api.model.APIIdentifier in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testAddComment.
@Test
public void testAddComment() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO);
APIIdentifier apiIdentifier = new APIIdentifier(API_PROVIDER, SAMPLE_API_NAME, SAMPLE_API_VERSION);
Mockito.when(apiMgtDAO.addComment(apiIdentifier, "testComment", "testUser")).thenReturn(1111);
apiConsumer.addComment(apiIdentifier, "testComment", "testUser");
Mockito.verify(apiMgtDAO, Mockito.times(1)).addComment(apiIdentifier, "testComment", "testUser");
}
use of org.wso2.carbon.apimgt.api.model.APIIdentifier in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testIsSubscribed.
@Test
public void testIsSubscribed() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
apiConsumer.apiMgtDAO = apiMgtDAO;
APIIdentifier apiIdentifier = new APIIdentifier(API_PROVIDER, SAMPLE_API_NAME, SAMPLE_API_VERSION);
Mockito.when(apiMgtDAO.isSubscribed(apiIdentifier, "testID")).thenReturn(true);
assertEquals(true, apiConsumer.isSubscribed(apiIdentifier, "testID"));
// Error Path
Mockito.when(apiMgtDAO.isSubscribed(apiIdentifier, "testID")).thenThrow(APIManagementException.class);
try {
apiConsumer.isSubscribed(apiIdentifier, "testID");
assertTrue(false);
} catch (APIManagementException e) {
assertTrue(true);
}
}
use of org.wso2.carbon.apimgt.api.model.APIIdentifier in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAllPaginatedAPIs.
@Test
public void testGetAllPaginatedAPIs() throws Exception {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
PowerMockito.mockStatic(GovernanceUtils.class);
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(false, true);
UserRegistry userRegistry1 = Mockito.mock(UserRegistry.class);
Mockito.when(registryService.getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt())).thenReturn(userRegistry1);
Mockito.when(registryService.getGovernanceSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry1);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
GenericArtifact[] genericArtifacts = new GenericArtifact[] { artifact };
Mockito.when(artifactManager.findGenericArtifacts(Mockito.anyMap())).thenReturn(genericArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact)).thenReturn(api);
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// artifact manager null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// generic artifact null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
Mockito.when(artifactManager.findGenericArtifacts(Mockito.anyMap())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
}
use of org.wso2.carbon.apimgt.api.model.APIIdentifier in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAPIsWithTag.
@Test
public void testGetAPIsWithTag() throws Exception {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.mockStatic(GovernanceUtils.class);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager(apiConsumer.registry, APIConstants.API_KEY)).thenReturn(artifactManager);
List<GovernanceArtifact> governanceArtifacts = new ArrayList<GovernanceArtifact>();
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
governanceArtifacts.add(artifact);
Mockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyString(), (UserRegistry) Mockito.anyObject(), Mockito.anyString())).thenReturn(governanceArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact)).thenReturn(api);
Mockito.when(artifact.getAttribute("overview_status")).thenReturn("PUBLISHED");
assertNotNull(apiConsumer.getAPIsWithTag("testTag", "testDomain"));
}
use of org.wso2.carbon.apimgt.api.model.APIIdentifier in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetTopRatedAPIs.
@Test
public void testGetTopRatedAPIs() throws APIManagementException, RegistryException {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
GenericArtifact[] genericArtifacts = new GenericArtifact[] { artifact };
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(genericArtifacts);
Mockito.when(artifact.getAttribute(Mockito.anyString())).thenReturn("PUBLISHED");
Mockito.when(artifact.getPath()).thenReturn("testPath");
Mockito.when(userRegistry.getAverageRating("testPath")).thenReturn((float) 20.0);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact, userRegistry)).thenReturn(api);
assertNotNull(apiConsumer.getTopRatedAPIs(10));
}
Aggregations