use of org.wso2.charon.core.objects.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdGetNotFound.
@Test
public void testApisApiIdDocumentsDocumentIdGetNotFound() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String documentId = UUID.randomUUID().toString();
String apiId = UUID.randomUUID().toString();
Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
Response response = apisApiService.apisApiIdDocumentsDocumentIdGet(apiId, documentId, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("Documntation not found"));
}
use of org.wso2.charon.core.objects.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisChangeLifecyclePostWithChecklistItemChange.
@Test
public void testApisChangeLifecyclePostWithChecklistItemChange() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
String checklist = "test1:test1,test2:test2";
String action = "CheckListItemChange";
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
Map<String, Boolean> lifecycleChecklistMap = new HashMap<>();
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String apiId = UUID.randomUUID().toString();
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).updateCheckListItem(apiId, action, lifecycleChecklistMap);
Response response = apisApiService.apisChangeLifecyclePost(action, apiId, checklist, null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("APPROVED"));
}
use of org.wso2.charon.core.objects.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdScopesPostWithInvalidscopebindingType.
@Test
public void testApisApiIdScopesPostWithInvalidscopebindingType() throws Exception {
printTestMethodName();
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();
Scope scope = new Scope("api_view", "api view");
Mockito.doNothing().when(apiPublisher).addScopeToTheApi(apiId, scope);
Response response = apisApiService.apisApiIdScopesPost(apiId, MappingUtil.scopeDto(scope, "permission"), null, null, getRequest());
assertEquals(response.getStatus(), 412);
}
use of org.wso2.charon.core.objects.User 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.charon.core.objects.User 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"));
}
Aggregations