Search in sources :

Example 56 with GenericArtifact

use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact 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));
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) API(org.wso2.carbon.apimgt.api.model.API) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 57 with GenericArtifact

use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact 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"));
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) GovernanceArtifact(org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact) ArrayList(java.util.ArrayList) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) API(org.wso2.carbon.apimgt.api.model.API) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 58 with GenericArtifact

use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact 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));
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) API(org.wso2.carbon.apimgt.api.model.API) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 59 with GenericArtifact

use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.

the class APIProviderImpl method changeAPILCCheckListItems.

@Override
public boolean changeAPILCCheckListItems(APIIdentifier apiIdentifier, int checkItem, boolean checkItemValue) throws APIManagementException {
    String providerTenantMode = apiIdentifier.getProviderName();
    boolean success = false;
    boolean isTenantFlowStarted = false;
    try {
        String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(providerTenantMode));
        if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
            isTenantFlowStarted = true;
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
        }
        GenericArtifact apiArtifact = getAPIArtifact(apiIdentifier);
        String status = null;
        try {
            if (apiArtifact != null) {
                if (checkItemValue && !apiArtifact.isLCItemChecked(checkItem, APIConstants.API_LIFE_CYCLE)) {
                    apiArtifact.checkLCItem(checkItem, APIConstants.API_LIFE_CYCLE);
                } else if (!checkItemValue && apiArtifact.isLCItemChecked(checkItem, APIConstants.API_LIFE_CYCLE)) {
                    apiArtifact.uncheckLCItem(checkItem, APIConstants.API_LIFE_CYCLE);
                }
                success = true;
            }
        } catch (GovernanceException e) {
            handleException("Error while setting registry lifecycle checklist items for the API: " + apiIdentifier.getApiName(), e);
        }
    } finally {
        if (isTenantFlowStarted) {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
    return success;
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException)

Example 60 with GenericArtifact

use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.

the class APIProviderImpl method getProvider.

/**
 * get details of provider
 *
 * @param providerName name of the provider
 * @return Provider
 * @throws org.wso2.carbon.apimgt.api.APIManagementException if failed to get Provider
 */
@Override
public Provider getProvider(String providerName) throws APIManagementException {
    Provider provider = null;
    String providerPath = APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.PROVIDERS_PATH + RegistryConstants.PATH_SEPARATOR + providerName;
    try {
        GenericArtifactManager artifactManager = APIUtil.getArtifactManager(registry, APIConstants.PROVIDER_KEY);
        if (artifactManager == null) {
            String errorMessage = "Failed to retrieve artifact manager when getting provider " + providerName;
            log.error(errorMessage);
            throw new APIManagementException(errorMessage);
        }
        Resource providerResource = registry.get(providerPath);
        String artifactId = providerResource.getUUID();
        if (artifactId == null) {
            throw new APIManagementException("artifact it is null");
        }
        GenericArtifact providerArtifact = artifactManager.getGenericArtifact(artifactId);
        provider = APIUtil.getProvider(providerArtifact);
    } catch (RegistryException e) {
        handleException("Failed to get Provider form : " + providerName, e);
    }
    return provider;
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) APIResource(org.wso2.carbon.apimgt.api.doc.model.APIResource) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) Provider(org.wso2.carbon.apimgt.api.model.Provider)

Aggregations

GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)141 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)84 Resource (org.wso2.carbon.registry.core.Resource)74 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)74 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)73 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)66 Registry (org.wso2.carbon.registry.core.Registry)65 Test (org.junit.Test)54 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)54 API (org.wso2.carbon.apimgt.api.model.API)51 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)40 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)38 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)36 DevPortalAPI (org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI)35 GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)35 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)26 UserStoreException (org.wso2.carbon.user.api.UserStoreException)24 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)22 Documentation (org.wso2.carbon.apimgt.api.model.Documentation)19