use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateApiEndpointUrl.
@Test(description = "Test add api with production endpoint")
public void testUpdateApiEndpointUrl() throws APIManagementException {
/**
* this test method verify the API Add with correct API object get invoked correctly
*/
Endpoint endpoint1 = new Endpoint.Builder().id(UUID.randomUUID().toString()).endpointConfig("http://localhost").name("endpoint1").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
Endpoint endpoint2 = new Endpoint.Builder().id(UUID.randomUUID().toString()).endpointConfig("http://localhost").name("endpoint2").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
Map<String, Endpoint> endpointMap = new HashMap<>();
endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, endpoint1);
endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, endpoint2);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id(UUID.randomUUID().toString()).endpoint(endpointMap);
apiBuilder.apiPermission("");
apiBuilder.permissionMap(null);
apiBuilder.policies(Collections.emptySet());
apiBuilder.apiPolicy(null);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
Mockito.when(apiDAO.getAPI(apiBuilder.getId())).thenReturn(apiBuilder.build());
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO, labelDao);
Mockito.when(apiDAO.getEndpoint(endpoint1.getId())).thenReturn(endpoint1);
Mockito.when(apiDAO.getEndpoint(endpoint2.getId())).thenReturn(endpoint2);
Mockito.when(apiDAO.getEndpoint(endpoint1.getName())).thenReturn(endpoint1);
Mockito.when(apiDAO.getEndpointByName(endpoint2.getName())).thenReturn(endpoint2);
Endpoint endpoint3 = new Endpoint.Builder(endpoint2).maxTps(1200).build();
Map<String, Endpoint> updatedEndpointMap = new HashMap<>(endpointMap);
updatedEndpointMap.replace(APIMgtConstants.SANDBOX_ENDPOINT, endpoint3);
apiBuilder.endpoint(updatedEndpointMap);
Mockito.when(apiDAO.getApiSwaggerDefinition(apiBuilder.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
apiPublisher.updateAPI(apiBuilder);
Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(apiBuilder.getId(), apiBuilder.build());
}
use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testSaveThumbnailImage.
@Test(description = "Save thumbnail image for API")
public void testSaveThumbnailImage() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
InputStream image = SampleTestObjectCreator.createDefaultThumbnailImage();
apiPublisher.saveThumbnailImage(API_ID, image, "png");
Mockito.verify(apiDAO, Mockito.times(1)).updateImage(API_ID, image, "png", USER);
}
use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateCheckListItemException.
@Test(description = "Exception when updating checklist item", expectedExceptions = APIManagementException.class)
public void testUpdateCheckListItemException() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(apiLifecycleManager.checkListItemEvent(lifecycleId, APIStatus.CREATED.getStatus(), APIMgtConstants.DEPRECATE_PREVIOUS_VERSIONS, true)).thenThrow(new LifecycleException("Couldn't get the lifecycle status of api ID " + uuid));
Map<String, Boolean> checklist = new HashMap<>();
checklist.put(APIMgtConstants.DEPRECATE_PREVIOUS_VERSIONS, true);
apiPublisher.updateCheckListItem(uuid, APIStatus.CREATED.getStatus(), checklist);
}
use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetScopeInformationForNonExistingScope.
@Test
public void testGetScopeInformationForNonExistingScope() throws APIManagementException, IOException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
KeyManager keyManager = Mockito.mock(KeyManager.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, keyManager);
String newSwagger = IOUtils.toString(new FileInputStream("src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization" + ".yaml"));
Mockito.when(apiDAO.getApiSwaggerDefinition("abcd")).thenReturn(newSwagger);
Scope scope = new Scope("apim:api_create", "apim:api_delete");
Mockito.when(keyManager.retrieveScope("apim:api_create")).thenReturn(scope);
try {
apiPublisher.getScopeInformationOfApi("abcd", "apim:api_delete");
Assert.fail();
} catch (APIManagementException e) {
Assert.assertEquals(e.getErrorHandler().getErrorCode(), 900981);
}
}
use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method getLabelsByType.
@Test(description = "get labels by STORE type")
public void getLabelsByType() throws Exception {
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(labelDao);
Mockito.when(labelDao.getLabelsByType("GATEWAY")).thenReturn(new ArrayList<Label>());
apiPublisher.getLabelsByType("GATEWAY");
Mockito.verify(labelDao, Mockito.times(1)).getLabelsByType("GATEWAY");
}
Aggregations