Search in sources :

Example 21 with Endpoint

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

the class ApiDAOImplIT method testAddDeleteGetEndpoint.

@Test
public void testAddDeleteGetEndpoint() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    apiDAO.addEndpoint(endpoint);
    apiDAO.deleteEndpoint(endpoint.getId());
    Endpoint retrieved = apiDAO.getEndpoint(endpoint.getId());
    Assert.assertNull(retrieved);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 22 with Endpoint

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

the class ApiDAOImplIT method testGetEndpointByName.

@Test(description = "Test getting endpoint by name")
public void testGetEndpointByName() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    apiDAO.addEndpoint(endpoint);
    Endpoint retrieved = apiDAO.getEndpointByName(endpoint.getName());
    Assert.assertEquals(endpoint, retrieved, TestUtil.printDiff(endpoint, retrieved));
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 23 with Endpoint

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

the class ApiDAOImplIT method testAddUpdateGetEndpoint.

@Test
public void testAddUpdateGetEndpoint() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    apiDAO.addEndpoint(SampleTestObjectCreator.createMockEndpoint());
    Endpoint updatedEndpoint = SampleTestObjectCreator.createUpdatedEndpoint();
    apiDAO.updateEndpoint(updatedEndpoint);
    Endpoint retrieved = apiDAO.getEndpoint(updatedEndpoint.getId());
    Assert.assertEquals(updatedEndpoint, retrieved);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 24 with Endpoint

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

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

Aggregations

Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)118 Test (org.testng.annotations.Test)66 API (org.wso2.carbon.apimgt.core.models.API)58 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)50 HashMap (java.util.HashMap)47 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)46 ArrayList (java.util.ArrayList)34 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)33 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)30 Test (org.junit.Test)27 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)24 HashSet (java.util.HashSet)23 Response (javax.ws.rs.core.Response)22 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)21 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)20 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)19 Map (java.util.Map)18 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)18