use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testFingerprintAfterUpdatingAPI.
@Test
public void testFingerprintAfterUpdatingAPI() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
String fingerprintBeforeUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfAPI(api.getId()));
Assert.assertNotNull(fingerprintBeforeUpdate);
Thread.sleep(1);
builder = SampleTestObjectCreator.createAlternativeAPI();
API substituteAPI = builder.build();
apiDAO.updateAPI(api.getId(), substituteAPI);
String fingerprintAfterUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfAPI(api.getId()));
Assert.assertNotNull(fingerprintAfterUpdate);
Assert.assertNotEquals(fingerprintBeforeUpdate, fingerprintAfterUpdate);
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddGetAllEndPointsAndUUIDs.
@Test
public void testAddGetAllEndPointsAndUUIDs() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
Endpoint endpoint1 = SampleTestObjectCreator.createMockEndpoint();
Endpoint endpoint2 = SampleTestObjectCreator.createAlternativeEndpoint();
Endpoint apiSpecificEndpoint = new Endpoint.Builder(SampleTestObjectCreator.createAlternativeEndpoint()).name("APISpecific").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).id(UUID.randomUUID().toString()).build();
apiDAO.addEndpoint(endpoint1);
apiDAO.addEndpoint(endpoint2);
apiDAO.addEndpoint(apiSpecificEndpoint);
List<Endpoint> endpointListAdd = new ArrayList<>();
endpointListAdd.add(endpoint1);
endpointListAdd.add(endpoint2);
List<Endpoint> endpointList = apiDAO.getEndpoints();
// verifying global endpoints
List<String> globalEndpointUuidList = apiDAO.getUUIDsOfGlobalEndpoints();
Assert.assertEquals(globalEndpointUuidList.size(), 2);
Assert.assertTrue(globalEndpointUuidList.contains(endpoint1.getId()));
Assert.assertTrue(globalEndpointUuidList.contains(endpoint2.getId()));
// verifying all endpoints
Assert.assertNotEquals(3, endpointList.size());
APIUtils.isListsEqualIgnoreOrder(endpointListAdd, endpointList, new EndPointComparator());
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testCreateNewAPIVersionAndGetAPIByUuidFailure.
@Test(description = "Create new API version with APIID and new API lifecycle add get failed", expectedExceptions = { APIMgtDAOException.class, APIManagementException.class })
public void testCreateNewAPIVersionAndGetAPIByUuidFailure() 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);
Mockito.when(apiDAO.getAPI("yyyyy")).thenThrow(new APIMgtDAOException(""));
apiPublisher.createNewAPIVersion("yyyyy", "2.0.0");
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddApiDefinitionErrorGettingSwaggerResource.
@Test(description = "Response not 200 when getting swagger resource from url when adding api from swagger resource", expectedExceptions = APIManagementException.class)
public void testAddApiDefinitionErrorGettingSwaggerResource() throws APIManagementException, LifecycleException, IOException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
HttpURLConnection httpURLConnection = Mockito.mock(HttpURLConnection.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
Mockito.when(httpURLConnection.getResponseCode()).thenReturn(400);
apiPublisher.addApiFromDefinition(httpURLConnection);
Mockito.verify(apiLifecycleManager, Mockito.times(0)).addLifecycle(APIMgtConstants.API_LIFECYCLE, USER);
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateDescription.
@Test(description = "Test add api with production endpoint")
public void testUpdateDescription() throws APIManagementException {
/**
* this test method verify the API Add with correct API object get invoked correctly
*/
Map<String, Endpoint> endpointMap = SampleTestObjectCreator.getMockEndpointMap();
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id(UUID.randomUUID().toString()).endpoint(endpointMap);
apiBuilder.apiPermission("");
apiBuilder.permissionMap(null);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.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);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO);
Mockito.when(apiDAO.getEndpoint(endpointMap.get(APIMgtConstants.PRODUCTION_ENDPOINT).getId())).thenReturn(endpointMap.get(APIMgtConstants.PRODUCTION_ENDPOINT));
Mockito.when(apiDAO.getEndpoint(endpointMap.get(APIMgtConstants.SANDBOX_ENDPOINT).getId())).thenReturn(endpointMap.get(APIMgtConstants.SANDBOX_ENDPOINT));
Mockito.when(apiDAO.getEndpointByName(endpointMap.get(APIMgtConstants.PRODUCTION_ENDPOINT).getName())).thenReturn(endpointMap.get(APIMgtConstants.PRODUCTION_ENDPOINT));
Mockito.when(apiDAO.getEndpointByName(endpointMap.get(APIMgtConstants.SANDBOX_ENDPOINT).getName())).thenReturn(endpointMap.get(APIMgtConstants.SANDBOX_ENDPOINT));
Mockito.when(apiDAO.getApiSwaggerDefinition(apiBuilder.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
apiBuilder.description("aaaaaa");
apiPublisher.updateAPI(apiBuilder);
Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(apiBuilder.getId(), apiBuilder.build());
}
Aggregations