Search in sources :

Example 1 with EndPointComparator

use of org.wso2.carbon.apimgt.core.util.EndPointComparator 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 2 with EndPointComparator

use of org.wso2.carbon.apimgt.core.util.EndPointComparator in project carbon-apimgt by wso2.

the class EndpointComparatorTestCase method testEndpointComparison.

@Test
public void testEndpointComparison() {
    EndPointComparator endPointComparator = new EndPointComparator();
    String testUUID = UUID.randomUUID().toString();
    Endpoint ep1 = new Endpoint.Builder().endpointConfig("{'type':'http','url':'http://localhost:8280'}").id(testUUID).maxTps(1000L).security("{'enabled':false}").name("Endpoint1").applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).type("http").build();
    Endpoint ep2 = new Endpoint.Builder().endpointConfig("{'type':'http','url':'http://localhost:8280'}").id(testUUID).maxTps(1000L).security("{'enabled':false}").name("Endpoint1").applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).type("http").build();
    Endpoint ep3 = new Endpoint.Builder().endpointConfig("{'type':'http','url':'http://localhost:8280'}").id(UUID.randomUUID().toString()).maxTps(2000L).security("{'enabled':true}").name("Endpoint1").applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).type("http").build();
    Endpoint ep4 = new Endpoint.Builder().endpointConfig("{'type':'http','url':'http://localhost:8280'}").id(UUID.randomUUID().toString()).maxTps(1000L).security("{'enabled':false}").name("Endpoint1").applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).type("http").build();
    Endpoint ep5 = new Endpoint.Builder().endpointConfig("{'type':'http','url':'http://localhost:6060'}").id(UUID.randomUUID().toString()).maxTps(1000L).security("{'enabled':false}").name("Endpoint1").applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).type("http").build();
    int endpointComparison1 = endPointComparator.compare(ep1, ep2);
    int endpointComparison2 = endPointComparator.compare(ep2, ep3);
    int endpointComparison3 = endPointComparator.compare(ep1, ep4);
    int endpointComparison4 = endPointComparator.compare(ep1, ep5);
    Assert.assertEquals(endpointComparison1, 0, "Endpoints are not equal. ");
    Assert.assertNotEquals(endpointComparison2, 0, "Endpoints are equal. ");
    Assert.assertEquals(endpointComparison3, 0, "Endpoints are not equal. ");
    Assert.assertNotEquals(endpointComparison4, 0, "Endpoints are equal. ");
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)2 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)2 ArrayList (java.util.ArrayList)1 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)1 EndPointComparator (org.wso2.carbon.apimgt.core.util.EndPointComparator)1