Search in sources :

Example 96 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testFingerprintAfterUpdatingThumbnailImage.

@Test
public void testFingerprintAfterUpdatingThumbnailImage() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    apiDAO.updateImage(api.getId(), SampleTestObjectCreator.createDefaultThumbnailImage(), "image/jpg", ADMIN);
    String fingerprintBeforeUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfAPIThumbnailImage(api.getId()));
    Assert.assertNotNull(fingerprintBeforeUpdate);
    Thread.sleep(1);
    apiDAO.updateImage(api.getId(), SampleTestObjectCreator.createAlternativeThumbnailImage(), "image/jpg", ADMIN);
    String fingerprintAfterUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfAPIThumbnailImage(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 97 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testUpdateAPIWithBlankwsdlUri.

@Test
public void testUpdateAPIWithBlankwsdlUri() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    Map permissionMap = new HashMap();
    permissionMap.put(APIMgtConstants.Permission.UPDATE, APIMgtConstants.Permission.UPDATE_PERMISSION);
    builder = SampleTestObjectCreator.createAlternativeAPI().permissionMap(permissionMap).wsdlUri(null);
    API substituteAPI = builder.build();
    apiDAO.updateAPI(api.getId(), substituteAPI);
    API apiFromDB = apiDAO.getAPI(api.getId());
    API expectedAPI = SampleTestObjectCreator.copyAPIIgnoringNonEditableFields(api, substituteAPI);
    Assert.assertNotNull(apiFromDB);
    Assert.assertEquals(apiFromDB, expectedAPI, TestUtil.printDiff(apiFromDB, expectedAPI));
}
Also used : HashMap(java.util.HashMap) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) HashMap(java.util.HashMap) Map(java.util.Map) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 98 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testAddApiAndResourceSpecificEndpointToApi.

@Test
public void testAddApiAndResourceSpecificEndpointToApi() throws APIMgtDAOException {
    Endpoint apiSpecificEndpoint = new Endpoint.Builder(SampleTestObjectCreator.createMockEndpoint()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
    Endpoint urlSpecificEndpoint = new Endpoint.Builder(SampleTestObjectCreator.createMockEndpoint()).id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("URI1").build();
    Endpoint endpointToInsert = SampleTestObjectCreator.createAlternativeEndpoint();
    Endpoint globalEndpoint = new Endpoint.Builder().applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).id(endpointToInsert.getId()).build();
    Map<String, Endpoint> apiEndpointMap = new HashMap();
    apiEndpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, apiSpecificEndpoint);
    apiEndpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, globalEndpoint);
    Map<String, Endpoint> uriTemplateEndpointMap = new HashMap();
    uriTemplateEndpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, urlSpecificEndpoint);
    Map<String, UriTemplate> uriTemplateMap = SampleTestObjectCreator.getMockUriTemplates();
    uriTemplateMap.forEach((k, v) -> {
        UriTemplate uriTemplate = new UriTemplate.UriTemplateBuilder(v).endpoint(uriTemplateEndpointMap).build();
        uriTemplateMap.replace(k, uriTemplate);
    });
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API api = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition).endpoint(apiEndpointMap).uriTemplates(uriTemplateMap).build();
    apiDAO.addEndpoint(endpointToInsert);
    apiDAO.addAPI(api);
    Map<String, Endpoint> retrievedApiEndpoint = apiDAO.getAPI(api.getId()).getEndpoint();
    Assert.assertTrue(apiDAO.isEndpointAssociated(globalEndpoint.getId()));
    Assert.assertEquals(apiEndpointMap, retrievedApiEndpoint);
    apiDAO.deleteAPI(api.getId());
    Endpoint retrievedGlobal = apiDAO.getEndpoint(globalEndpoint.getId());
    Assert.assertNotNull(retrievedGlobal);
    Assert.assertEquals(endpointToInsert, retrievedGlobal);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) HashMap(java.util.HashMap) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 99 with API

use of org.wso2.carbon.apimgt.core.models.API 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 100 with API

use of org.wso2.carbon.apimgt.core.models.API 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)

Aggregations

API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)320 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)132 HashMap (java.util.HashMap)129 ArrayList (java.util.ArrayList)112 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)106 Test (org.junit.Test)83 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)83 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)82 SQLException (java.sql.SQLException)75 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)70 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)65 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)61 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)60 Connection (java.sql.Connection)58 Response (javax.ws.rs.core.Response)58