Search in sources :

Example 11 with PublisherAPIProduct

use of org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct in project carbon-apimgt by wso2.

the class RegistryPersistenceImplTestCase method testGetPublisherAPIProduct.

@Test
public void testGetPublisherAPIProduct() 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.getSampleAPIProductArtifact();
    String apiProductId = artifact.getId();
    APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, artifact);
    Organization org = new Organization(SUPER_TENANT_DOMAIN);
    PublisherAPIProduct productAPI = apiPersistenceInstance.getPublisherAPIProduct(org, apiProductId);
    Assert.assertEquals("API Product UUID does not match", apiProductId, productAPI.getId());
}
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) Resource(org.wso2.carbon.registry.core.Resource) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) 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 12 with PublisherAPIProduct

use of org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct in project carbon-apimgt by wso2.

the class RegistryPersistenceImplTestCase method testUpdateAPIProduct.

@Test
public void testUpdateAPIProduct() throws APIPersistenceException, RegistryException, APIManagementException {
    PublisherAPIProduct publisherAPI = new PublisherAPIProduct();
    publisherAPI.setDescription("Modified description");
    APIProduct api = APIProductMapper.INSTANCE.toApiProduct(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.getSampleAPIProductArtifact();
    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.getSampleAPIProductArtifact();
    updatedArtifact.setAttribute(APIConstants.API_OVERVIEW_DESCRIPTION, api.getDescription());
    PowerMockito.when(RegistryPersistenceUtil.createAPIProductArtifactContent(any(GenericArtifact.class), any(APIProduct.class))).thenReturn(updatedArtifact);
    Organization org = new Organization(SUPER_TENANT_DOMAIN);
    APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, existArtifact);
    PublisherAPIProduct updatedAPI = apiPersistenceInstance.updateAPIProduct(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) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) Tag(org.wso2.carbon.registry.core.Tag) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

PublisherAPIProduct (org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct)12 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)8 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)8 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)7 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)6 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)6 Registry (org.wso2.carbon.registry.core.Registry)6 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)6 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)4 Resource (org.wso2.carbon.registry.core.Resource)4 Matchers.anyString (org.mockito.Matchers.anyString)3 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)3 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)3 ResourceImpl (org.wso2.carbon.registry.core.ResourceImpl)3 Tag (org.wso2.carbon.registry.core.Tag)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 QName (javax.xml.namespace.QName)2 OASPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException)2