Search in sources :

Example 21 with Endpoint

use of org.wso2.carbon.governance.api.endpoints.dataobjects.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.governance.api.endpoints.dataobjects.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.governance.api.endpoints.dataobjects.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.governance.api.endpoints.dataobjects.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.governance.api.endpoints.dataobjects.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)114 HashMap (java.util.HashMap)90 IOException (java.io.IOException)84 ArrayList (java.util.ArrayList)77 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)70 Test (org.junit.Test)62 API (org.wso2.carbon.apimgt.core.models.API)58 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)50 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)50 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)46 Map (java.util.Map)44 HashSet (java.util.HashSet)36 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)33 URL (java.net.URL)31 CharonException (org.wso2.charon3.core.exceptions.CharonException)31 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)30 OMElement (org.apache.axiom.om.OMElement)28 Response (javax.ws.rs.core.Response)27 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)27