use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddUpdateAPIFromWSDLArchive.
@Test(description = "Test adding an API from WSDL archive")
public void testAddUpdateAPIFromWSDLArchive() throws APIManagementException, LifecycleException, IOException {
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(SampleTestObjectCreator.getMockEndpointMap());
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APILifecycleManager apiLifecycleManager = getDefaultMockedAPILifecycleManager();
PolicyDAO policyDAO = getDefaultMockedPolicyDAO();
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO, labelDao);
String endpointId = apiBuilder.getEndpoint().get("production").getId();
Endpoint endpoint = new Endpoint.Builder().id(endpointId).name("testEndpoint").build();
Mockito.when(apiDAO.getEndpoint(endpointId)).thenReturn(endpoint);
apiPublisher.addAPIFromWSDLArchive(apiBuilder, SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream(), true);
Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
Mockito.verify(apiDAO, Mockito.times(1)).addOrUpdateWSDLArchive(Mockito.eq(apiBuilder.getId()), Mockito.anyObject(), Mockito.eq(USER));
apiPublisher.updateAPIWSDLArchive(apiBuilder.getId(), SampleTestObjectCreator.createAlternativeWSDL11ArchiveInputStream());
Mockito.verify(apiDAO, Mockito.times(2)).addOrUpdateWSDLArchive(Mockito.eq(apiBuilder.getId()), Mockito.anyObject(), Mockito.eq(USER));
}
use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetPolicyByName.
@Test(description = "Get all policy by name")
public void testGetPolicyByName() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy policy = Mockito.mock(Policy.class);
policy.setPolicyName(POLICY_NAME);
APIPublisherImpl apiPublisher = getApiPublisherImpl(policyDAO);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME)).thenReturn(policy);
apiPublisher.getPolicyByName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
Mockito.verify(policyDAO, Mockito.times(1)).getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
// Error path
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME)).thenThrow(APIMgtDAOException.class);
try {
apiPublisher.getPolicyByName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error while retrieving Policy for level: " + APIMgtAdminService.PolicyLevel.application + ", name: " + POLICY_NAME);
}
}
use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testCheckIfAPIExistForValidUuid.
@Test(description = "Check if api exist with valid uuid")
public void testCheckIfAPIExistForValidUuid() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.when(apiDAO.isAPIExists("zzzzz")).thenReturn(true);
Assert.assertTrue(apiPublisher.isAPIExists("zzzzz"));
}
use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetLastUpdatedTimeOfEndpoint.
@Test(description = "Get last updated time of endpoint")
public void testGetLastUpdatedTimeOfEndpoint() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.when(apiDAO.getLastUpdatedTimeOfEndpoint(ENDPOINT_ID)).thenReturn("2017-03-19T13:45:30");
apiPublisher.getLastUpdatedTimeOfEndpoint(ENDPOINT_ID);
Mockito.verify(apiDAO, Mockito.times(1)).getLastUpdatedTimeOfEndpoint(ENDPOINT_ID);
}
use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testRemoveDocumentationInfo.
@Test(description = "Remove Documentation Info")
public void testRemoveDocumentationInfo() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
apiPublisher.removeDocumentation(DOC_ID);
Mockito.verify(apiDAO, Mockito.times(1)).deleteDocument(DOC_ID);
}
Aggregations