Search in sources :

Example 51 with ApiDAO

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);
}
Also used : CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 52 with ApiDAO

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());
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) EndPointComparator(org.wso2.carbon.apimgt.core.util.EndPointComparator) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 53 with ApiDAO

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");
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 54 with ApiDAO

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);
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) HttpURLConnection(java.net.HttpURLConnection) LifecycleState(org.wso2.carbon.lcm.core.impl.LifecycleState) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 55 with ApiDAO

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());
}
Also used : APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Aggregations

ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)315 Test (org.testng.annotations.Test)305 API (org.wso2.carbon.apimgt.core.models.API)210 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)108 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)102 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)65 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)62 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)59 BeforeTest (org.testng.annotations.BeforeTest)50 ArrayList (java.util.ArrayList)48 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)47 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)46 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)45 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)43 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)36 HashMap (java.util.HashMap)31 SQLException (java.sql.SQLException)30 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)30 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)27