Search in sources :

Example 1 with ResourceImpl

use of org.wso2.carbon.registry.core.ResourceImpl in project carbon-apimgt by wso2.

the class RegistryPersistenceImplTestCase method testGetDevPortalAPI.

@Test
public void testGetDevPortalAPI() throws Exception {
    Registry registry = Mockito.mock(UserRegistry.class);
    Resource resource = new ResourceImpl();
    Mockito.when(registry.get(anyString())).thenReturn(resource);
    Tag[] tags = new Tag[1];
    Tag tag = new Tag();
    tag.setTagName("testTag");
    tags[0] = tag;
    Mockito.when(registry.getTags(anyString())).thenReturn(tags);
    GenericArtifact artifact = PersistenceHelper.getSampleAPIArtifact();
    String apiUUID = artifact.getId();
    String apiDescription = artifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION);
    APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, artifact);
    Organization org = new Organization(SUPER_TENANT_DOMAIN);
    DevPortalAPI devAPI = apiPersistenceInstance.getDevPortalAPI(org, apiUUID);
    Assert.assertEquals("API UUID does not match", apiUUID, devAPI.getId());
    Assert.assertEquals("API Description does not match", apiDescription, devAPI.getDescription());
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) Tag(org.wso2.carbon.registry.core.Tag) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ResourceImpl

use of org.wso2.carbon.registry.core.ResourceImpl in project carbon-apimgt by wso2.

the class RegistryPersistenceImplTestCase method testUpdateAPI.

@Test
public void testUpdateAPI() throws APIPersistenceException, RegistryException, APIManagementException {
    PublisherAPI publisherAPI = new PublisherAPI();
    publisherAPI.setDescription("Modified description");
    API api = APIMapper.INSTANCE.toApi(publisherAPI);
    Registry registry = Mockito.mock(UserRegistry.class);
    Resource resource = new ResourceImpl();
    Mockito.when(registry.get(anyString())).thenReturn(resource);
    Tag[] tags = new Tag[0];
    Mockito.when(registry.getTags(anyString())).thenReturn(tags);
    GenericArtifact existArtifact = PersistenceHelper.getSampleAPIArtifact();
    String apiUUID = existArtifact.getId();
    PowerMockito.mockStatic(RegistryPersistenceUtil.class);
    GenericArtifactManager manager = Mockito.mock(GenericArtifactManager.class);
    PowerMockito.when(RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY)).thenReturn(manager);
    Mockito.when(manager.getGenericArtifact(apiUUID)).thenReturn(existArtifact);
    Mockito.doNothing().when(manager).updateGenericArtifact(existArtifact);
    PowerMockito.when(RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY)).thenReturn(manager);
    GenericArtifact updatedArtifact = PersistenceHelper.getSampleAPIArtifact();
    updatedArtifact.setAttribute(APIConstants.API_OVERVIEW_DESCRIPTION, api.getDescription());
    PowerMockito.when(RegistryPersistenceUtil.createAPIArtifactContent(any(GenericArtifact.class), any(API.class))).thenReturn(updatedArtifact);
    Organization org = new Organization(SUPER_TENANT_DOMAIN);
    APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, existArtifact);
    PublisherAPI updatedAPI = apiPersistenceInstance.updateAPI(org, publisherAPI);
    Assert.assertEquals("Updated API description does not match", "Modified description", updatedAPI.getDescription());
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) Matchers.anyString(org.mockito.Matchers.anyString) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) Tag(org.wso2.carbon.registry.core.Tag) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ResourceImpl

use of org.wso2.carbon.registry.core.ResourceImpl in project carbon-apimgt by wso2.

the class RegistryPersistenceImplTestCase method testGetPublisherAPI.

@Test
public void testGetPublisherAPI() throws Exception {
    Registry registry = Mockito.mock(UserRegistry.class);
    Resource resource = new ResourceImpl();
    Mockito.when(registry.get(anyString())).thenReturn(resource);
    Tag[] tags = new Tag[1];
    Tag tag = new Tag();
    tag.setTagName("testTag");
    tags[0] = tag;
    Mockito.when(registry.getTags(anyString())).thenReturn(tags);
    GenericArtifact artifact = PersistenceHelper.getSampleAPIArtifact();
    String apiUUID = artifact.getId();
    String apiProviderName = artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER);
    apiProviderName = RegistryPersistenceUtil.replaceEmailDomain(apiProviderName);
    String apiName = artifact.getAttribute(APIConstants.API_OVERVIEW_NAME);
    String apiDescription = artifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION);
    String apiVersion = artifact.getAttribute(APIConstants.API_OVERVIEW_VERSION);
    String apiPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiProviderName + RegistryConstants.PATH_SEPARATOR + apiName + RegistryConstants.PATH_SEPARATOR + apiVersion + RegistryConstants.PATH_SEPARATOR + "api";
    PowerMockito.when(GovernanceUtils.getArtifactPath(registry, apiUUID)).thenReturn(apiPath);
    APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, artifact);
    Organization org = new Organization(SUPER_TENANT_DOMAIN);
    PublisherAPI publisherAPI = apiPersistenceInstance.getPublisherAPI(org, apiUUID);
    Assert.assertEquals("API UUID does not match", apiUUID, publisherAPI.getId());
    Assert.assertEquals("API Description does not match", apiDescription, publisherAPI.getDescription());
    Assert.assertEquals("API audience does not match", artifact.getAttribute(APIConstants.API_OVERVIEW_AUDIENCE), publisherAPI.getAudience());
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) Tag(org.wso2.carbon.registry.core.Tag) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ResourceImpl

use of org.wso2.carbon.registry.core.ResourceImpl in project carbon-apimgt by wso2.

the class APIMapperTestCase method setupClass.

@Before
public void setupClass() throws Exception {
    System.setProperty("carbon.home", "");
    ServiceReferenceHolder serviceRefHolder = Mockito.mock(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceRefHolder);
    RealmService realmService = Mockito.mock(RealmService.class);
    PowerMockito.when(serviceRefHolder.getRealmService()).thenReturn(realmService);
    TenantManager tenantManager = Mockito.mock(TenantManager.class);
    PowerMockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    PowerMockito.when(tenantManager.getTenantId(SUPER_TENANT_DOMAIN)).thenReturn(SUPER_TENANT_ID);
    registry = Mockito.mock(Registry.class);
    PowerMockito.mockStatic(MultitenantUtils.class);
    Resource resource = new ResourceImpl();
    Mockito.when(registry.get(anyString())).thenReturn(resource);
    Tag[] tags = new Tag[1];
    Tag tag = new Tag();
    tag.setTagName("testTag");
    tags[0] = tag;
    Mockito.when(registry.getTags(anyString())).thenReturn(tags);
    PowerMockito.mockStatic(GovernanceUtils.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PrivilegedCarbonContext privilegedContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedContext);
    GenericArtifact genericArtifact = PersistenceHelper.getSampleAPIArtifact();
    api = RegistryPersistenceUtil.getAPI(genericArtifact, registry);
    GenericArtifact productGenericArtifact = PersistenceHelper.getSampleAPIProductArtifact();
    product = RegistryPersistenceUtil.getAPIProduct(productGenericArtifact, registry);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder) GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) RealmService(org.wso2.carbon.user.core.service.RealmService) Resource(org.wso2.carbon.registry.core.Resource) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Registry(org.wso2.carbon.registry.core.Registry) Tag(org.wso2.carbon.registry.core.Tag) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Before(org.junit.Before)

Example 5 with ResourceImpl

use of org.wso2.carbon.registry.core.ResourceImpl in project carbon-apimgt by wso2.

the class RegistryPersistenceUtilTestCase method setupClass.

@Before
public void setupClass() throws Exception {
    System.setProperty("carbon.home", "");
    ServiceReferenceHolder serviceRefHolder = Mockito.mock(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceRefHolder);
    RealmService realmService = Mockito.mock(RealmService.class);
    PowerMockito.when(serviceRefHolder.getRealmService()).thenReturn(realmService);
    TenantManager tenantManager = Mockito.mock(TenantManager.class);
    PowerMockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    PowerMockito.when(tenantManager.getTenantId(SUPER_TENANT_DOMAIN)).thenReturn(SUPER_TENANT_ID);
    registry = Mockito.mock(Registry.class);
    PowerMockito.mockStatic(MultitenantUtils.class);
    Resource resource = new ResourceImpl();
    Mockito.when(registry.get(anyString())).thenReturn(resource);
    Tag[] tags = new Tag[1];
    Tag tag = new Tag();
    tag.setTagName("testTag");
    tags[0] = tag;
    Mockito.when(registry.getTags(anyString())).thenReturn(tags);
    PowerMockito.mockStatic(GovernanceUtils.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PrivilegedCarbonContext privilegedContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedContext);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) RealmService(org.wso2.carbon.user.core.service.RealmService) Resource(org.wso2.carbon.registry.core.Resource) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) Tag(org.wso2.carbon.registry.core.Tag) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Before(org.junit.Before)

Aggregations

Resource (org.wso2.carbon.registry.core.Resource)43 ResourceImpl (org.wso2.carbon.registry.core.ResourceImpl)43 Test (org.junit.Test)37 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)36 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)20 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)20 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)20 Registry (org.wso2.carbon.registry.core.Registry)17 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)17 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)16 Matchers.anyString (org.mockito.Matchers.anyString)12 Collection (org.wso2.carbon.registry.core.Collection)12 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)10 API (org.wso2.carbon.apimgt.api.model.API)9 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)9 CollectionImpl (org.wso2.carbon.registry.core.CollectionImpl)9 Tag (org.wso2.carbon.registry.core.Tag)9 ResourceDO (org.wso2.carbon.registry.core.jdbc.dataobjects.ResourceDO)9 InputStream (java.io.InputStream)7 ArrayInputStream (org.apache.derby.iapi.services.io.ArrayInputStream)6