use of org.wso2.carbon.apimgt.persistence.dto.PublisherAPI 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());
}
use of org.wso2.carbon.apimgt.persistence.dto.PublisherAPI 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());
}
use of org.wso2.carbon.apimgt.persistence.dto.PublisherAPI in project carbon-apimgt by wso2.
the class APIMapperTestCase method testAPItoPublisherApiAndBack.
@Test
public void testAPItoPublisherApiAndBack() throws GovernanceException, APIManagementException {
PublisherAPI pubAPI = APIMapper.INSTANCE.toPublisherApi(api);
Assert.assertEquals("API name does not match", api.getId().getName(), pubAPI.getApiName());
Assert.assertEquals("API uuid does not match", api.getUuid(), pubAPI.getId());
Assert.assertTrue("Mapped api does not have status", pubAPI.toString().contains(api.getStatus()));
API mappedAPI = APIMapper.INSTANCE.toApi(pubAPI);
Assert.assertEquals("Mapped api name does not match", mappedAPI.getId().getName(), api.getId().getName());
}
use of org.wso2.carbon.apimgt.persistence.dto.PublisherAPI in project carbon-apimgt by wso2.
the class APIProviderImplTest method testUpdateAPIforStateChange_ToPublished.
@Test
public void testUpdateAPIforStateChange_ToPublished() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, APIPersistenceException, XMLStreamException {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
Set<String> environments = new HashSet<String>();
environments.add("Production");
environments.add("Sandbox");
API api = new API(apiId);
api.setContext("/test");
api.setStatus(APIConstants.CREATED);
api.setAsDefaultVersion(true);
api.setEnvironments(environments);
api.setOrganization("carbon.super");
Mockito.when(apimgtDAO.getPublishedDefaultVersion(apiId)).thenReturn("1.0.0");
Map<String, String> failedGWEnv = new HashMap<String, String>();
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, null, null);
Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getConfigSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
PublisherAPI publisherAPI = Mockito.mock(PublisherAPI.class);
PowerMockito.when(apiPersistenceInstance.addAPI(any(Organization.class), any(PublisherAPI.class))).thenReturn(publisherAPI);
apiProvider.addAPI(api);
// Mock Updating API
Resource apiSourceArtifact = Mockito.mock(Resource.class);
Mockito.when(apiSourceArtifact.getUUID()).thenReturn("12640983654");
String apiSourcePath = "path";
PowerMockito.when(APIUtil.getAPIPath(api.getId())).thenReturn(apiSourcePath);
PowerMockito.when(apiProvider.registry.get(apiSourcePath)).thenReturn(apiSourceArtifact);
Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_STATUS)).thenReturn("CREATED");
Mockito.when(artifactManager.getGenericArtifact(apiSourceArtifact.getUUID())).thenReturn(artifact);
PowerMockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
Mockito.when(artifact.getId()).thenReturn("12640983654");
PowerMockito.when(GovernanceUtils.getArtifactPath(apiProvider.registry, "12640983654")).thenReturn(apiSourcePath);
Mockito.doNothing().when(artifactManager).updateGenericArtifact(artifact);
apiProvider.updateAPIforStateChange(api, APIConstants.CREATED, APIConstants.PUBLISHED);
// From the 2 environments, only 1 was successful
Assert.assertEquals(2, api.getEnvironments().size());
}
use of org.wso2.carbon.apimgt.persistence.dto.PublisherAPI in project carbon-apimgt by wso2.
the class APIProviderImplTest method testUpdateAPIforStateChange_ToRetired.
@Test
public void testUpdateAPIforStateChange_ToRetired() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, WorkflowException, APIPersistenceException, XMLStreamException {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
Set<String> environments = new HashSet<String>();
environments.add("Production");
environments.add("Sandbox");
API api = new API(apiId);
api.setContext("/test");
api.setStatus(APIConstants.CREATED);
api.setAsDefaultVersion(true);
api.setEnvironments(environments);
api.setOrganization("carbon.super");
Mockito.when(apimgtDAO.getPublishedDefaultVersion(apiId)).thenReturn("1.0.0");
Map<String, String> failedGWEnv = new HashMap<String, String>();
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, null, null);
Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getConfigSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
PublisherAPI publisherAPI = Mockito.mock(PublisherAPI.class);
PowerMockito.when(apiPersistenceInstance.addAPI(any(Organization.class), any(PublisherAPI.class))).thenReturn(publisherAPI);
apiProvider.addAPI(api);
// Mock Updating API
Resource apiSourceArtifact = Mockito.mock(Resource.class);
Mockito.when(apiSourceArtifact.getUUID()).thenReturn("12640983654");
String apiSourcePath = "path";
PowerMockito.when(APIUtil.getAPIPath(api.getId())).thenReturn(apiSourcePath);
PowerMockito.when(apiProvider.registry.get(apiSourcePath)).thenReturn(apiSourceArtifact);
Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_STATUS)).thenReturn("CREATED");
Mockito.when(artifactManager.getGenericArtifact(apiSourceArtifact.getUUID())).thenReturn(artifact);
PowerMockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
Mockito.when(artifact.getId()).thenReturn("12640983654");
PowerMockito.when(GovernanceUtils.getArtifactPath(apiProvider.registry, "12640983654")).thenReturn(apiSourcePath);
Mockito.doNothing().when(artifactManager).updateGenericArtifact(artifact);
WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
boolean status = apiProvider.updateAPIforStateChange(api, APIConstants.CREATED, APIConstants.RETIRED);
Assert.assertEquals(2, api.getEnvironments().size());
Assert.assertEquals(true, status);
}
Aggregations