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());
}
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());
}
Aggregations