use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdWsdlGetNone.
@Test
public void testApisApiIdWsdlGetNone() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.doReturn(false).when(apiPublisher).isWSDLExists(api.getId());
Response response = apisApiService.apisApiIdWsdlGet(api.getId(), null, null, getRequest());
assertEquals(response.getStatus(), 204);
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisChangeLifecyclePostWithoutChecklistItemNonChange.
@Test
public void testApisChangeLifecyclePostWithoutChecklistItemNonChange() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
String checklist = "test1:test1,test2:test2";
String action = "CheckListItemChangeDifferent";
Map<String, Boolean> lifecycleChecklistMap = new HashMap<>();
if (checklist != null) {
String[] checkList = checklist.split(",");
for (String checkList1 : checkList) {
StringTokenizer attributeTokens = new StringTokenizer(checkList1, ":");
String attributeName = attributeTokens.nextToken();
Boolean attributeValue = Boolean.valueOf(attributeTokens.nextToken());
lifecycleChecklistMap.put(attributeName, attributeValue);
}
}
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.CREATED);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String apiId = UUID.randomUUID().toString();
Mockito.doReturn(workflowResponse).doThrow(new IllegalArgumentException()).when(apiPublisher).updateAPIStatus(apiId, action, lifecycleChecklistMap);
Response response = apisApiService.apisChangeLifecyclePost(action, apiId, checklist, null, null, getRequest());
assertEquals(response.getStatus(), 202);
assertTrue(response.getEntity().toString().contains("CREATED"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisImportDefinitionPostException.
@Test
public void testApisImportDefinitionPostException() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("swagger.json").getFile());
FileInputStream fis = null;
fis = new FileInputStream(file);
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).addApiFromDefinition(fis);
Response response = apisApiService.apisImportDefinitionPost(null, fis, null, null, null, null, null, null, getRequest());
fis.close();
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("API Type specified is invalid"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdThumbnailGet.
@Test
public void testApisApiIdThumbnailGet() throws Exception {
printTestMethodName();
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("api1_thumbnail.png").getFile());
FileInputStream fis = null;
fis = new FileInputStream(file);
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String apiId = UUID.randomUUID().toString();
Mockito.doReturn(fis).doThrow(new IllegalArgumentException()).when(apiPublisher).getThumbnailImage(apiId);
Response response = apisApiService.apisApiIdThumbnailGet(apiId, null, null, getRequest());
fis.close();
assertEquals(response.getStatus(), 200);
assertTrue(response.getStringHeaders().get("Content-Disposition").toString().contains("filename"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisGet.
@Test
public void testApisGet() throws Exception {
printTestMethodName();
List<API> apis = new ArrayList<>();
apis.add(SampleTestObjectCreator.createDefaultAPI().name("newAPI1").build());
apis.add(SampleTestObjectCreator.createDefaultAPI().name("newAPI2").build());
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doReturn(apis).doThrow(new IllegalArgumentException()).when(apiPublisher).searchAPIs(10, 0, "");
Response response = apisApiService.apisGet(10, 0, "", null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("newAPI1"));
assertTrue(response.getEntity().toString().contains("newAPI2"));
}
Aggregations