use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImplTestCase method testCompositeApisApiIdGet.
@Test
public void testCompositeApisApiIdGet() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String apiID = UUID.randomUUID().toString();
CompositeApisApiServiceImpl compositeApisApiService = new CompositeApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
CompositeAPI compositeAPI = SampleTestObjectCreator.createCompositeAPIModelBuilder().build();
Mockito.when(apiStore.isCompositeAPIExist(apiID)).thenReturn(Boolean.TRUE);
Mockito.when(apiStore.getCompositeAPIbyId(apiID)).thenReturn(compositeAPI);
Response response = compositeApisApiService.compositeApisApiIdGet(apiID, null, null, request);
Assert.assertEquals(200, response.getStatus());
Assert.assertTrue(response.getEntity().toString().contains(compositeAPI.getName()));
}
use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImplTestCase method testCompositeApisGet.
@Test
public void testCompositeApisGet() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String query = "*";
CompositeApisApiServiceImpl compositeApisApiService = new CompositeApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
CompositeAPI compositeAPI1 = SampleTestObjectCreator.createCompositeAPIModelBuilder().build();
CompositeAPI compositeAPI2 = SampleTestObjectCreator.createCompositeAPIModelBuilder().build();
List<CompositeAPI> compositeAPIList = new ArrayList<>();
compositeAPIList.add(compositeAPI1);
compositeAPIList.add(compositeAPI2);
Mockito.when(apiStore.searchCompositeAPIs(query, 0, 10)).thenReturn(compositeAPIList);
Response response = compositeApisApiService.compositeApisGet(10, 0, query, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisPost.
@Override
public Response compositeApisPost(CompositeAPIDTO body, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
CompositeAPI.Builder apiBuilder = CompositeAPIMappingUtil.toAPI(body);
APIStore apiStore = RestApiUtil.getConsumer(username);
Application app = apiStore.getApplicationByUuid(apiBuilder.getApplicationId());
// One application can only have one Composite API in default implementation
if (apiStore.getAPISubscriptionsByApplication(app, ApiType.COMPOSITE).size() > 0) {
String errorMessage = "A Composite API already exists for application : " + app.getId();
APIMgtResourceAlreadyExistsException e = new APIMgtResourceAlreadyExistsException(errorMessage, ExceptionCodes.COMPOSITE_API_ALREADY_EXISTS);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, app.getId());
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
apiStore.addCompositeApi(apiBuilder);
CompositeAPI returnAPI = apiStore.getCompositeAPIbyId(apiBuilder.build().getId());
return Response.status(Response.Status.CREATED).entity(CompositeAPIMappingUtil.toCompositeAPIDTO(returnAPI)).build();
} catch (APIManagementException e) {
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_NAME, body.getName());
paramList.put(APIMgtConstants.ExceptionsConstants.API_VERSION, body.getVersion());
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class CompositeAPIMappingUtil method toCompositeAPIDTO.
/**
* Converts {@link CompositeAPI} to a {@link CompositeAPIDTO}.
*
* @param api CompositeAPI
* @return API DTO
*/
public static CompositeAPIDTO toCompositeAPIDTO(CompositeAPI api) {
CompositeAPIDTO compositeAPIDTO = new CompositeAPIDTO();
compositeAPIDTO.setId(api.getId());
compositeAPIDTO.setName(api.getName());
compositeAPIDTO.setProvider(api.getProvider());
compositeAPIDTO.setVersion(api.getVersion());
compositeAPIDTO.setContext(api.getContext());
compositeAPIDTO.setDescription(api.getDescription());
compositeAPIDTO.setLabels(new ArrayList<>(api.getLabels()));
compositeAPIDTO.setApplicationId(api.getApplicationId());
compositeAPIDTO.hasOwnGateway(api.hasOwnGateway());
return compositeAPIDTO;
}
use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImplTestCase method testCompositeApisPost.
@Test
public void testCompositeApisPost() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
CompositeApisApiServiceImpl compositeApisApiService = new CompositeApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
CompositeAPI compositeAPI = SampleTestObjectCreator.createCompositeAPIModelBuilder().build();
CompositeAPIDTO compositeAPIDTO = CompositeAPIMappingUtil.toCompositeAPIDTO(compositeAPI);
Application application = SampleTestObjectCreator.createDefaultApplication();
Mockito.when(apiStore.getApplicationByUuid(UUID.randomUUID().toString())).thenReturn(application);
Mockito.when(apiStore.getCompositeAPIbyId(compositeAPI.getId())).thenReturn(compositeAPI);
Response response = compositeApisApiService.compositeApisPost(compositeAPIDTO, request);
Assert.assertEquals(201, response.getStatus());
}
Aggregations