Search in sources :

Example 81 with Endpoint

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

the class APIMappingUtilTestCase method testToAPIDTO.

@Test
public void testToAPIDTO() throws APIManagementException {
    String api1Id = UUID.randomUUID().toString();
    Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
    Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
    API api1 = createApi("provider1", api1Id, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
    APIMappingUtil apiMappingUtil = new APIMappingUtil();
    APIDTO apidto = apiMappingUtil.toAPIDTO(api1);
    Assert.assertEquals(apidto.getName(), "testapi1");
}
Also used : APIDTO(org.wso2.carbon.apimgt.rest.api.store.dto.APIDTO) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 82 with Endpoint

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

the class APIMappingUtilTestCase method testAPIListDTO.

@Test
public void testAPIListDTO() throws APIManagementException {
    String api1Id = UUID.randomUUID().toString();
    Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
    Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
    API api1 = createApi("provider1", api1Id, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
    String api2Id = UUID.randomUUID().toString();
    Endpoint api2SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd123").build();
    Endpoint api2ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef123").build();
    API api2 = createApi("provider1", api2Id, "testapi2", "1.0.0", "Test API 2 - version 1.0.0", createEndpointTypeToIdMap(api2SandBoxEndpointId, api2ProdEndpointId)).build();
    List<API> apiList = new ArrayList<>();
    apiList.add(api1);
    apiList.add(api2);
    APIMappingUtil apiMappingUtil = new APIMappingUtil();
    APIListDTO apiListDTO = apiMappingUtil.toAPIListDTO(apiList);
    Assert.assertEquals(apiListDTO.getList().get(0).getName(), "testapi1");
    Assert.assertEquals(apiListDTO.getList().get(1).getName(), "testapi2");
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 83 with Endpoint

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

the class APIPublisherImplTestCase method testGetEndpoint.

@Test(description = "Test getting endpoint")
public void testGetEndpoint() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    String endpointId = endpoint.getId();
    APIPublisher apiPublisher = getApiPublisherImpl(apiDAO);
    Mockito.when(apiDAO.getEndpoint(endpointId)).thenReturn(endpoint);
    apiPublisher.getEndpoint(endpointId);
    Mockito.verify(apiDAO, Mockito.times(1)).getEndpoint(endpointId);
    // Error path
    Mockito.when(apiDAO.getEndpoint(endpointId)).thenThrow(APIMgtDAOException.class);
    try {
        apiPublisher.getEndpoint(endpointId);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Failed to get Endpoint : " + endpointId);
    }
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 84 with Endpoint

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

the class APIPublisherImplTestCase method testUpdateApiEndpointWithAlreadyAvailableEndpointName.

@Test(description = "Test add api with production endpoint", expectedExceptions = { APIManagementException.class }, expectedExceptionsMessageRegExp = "Endpoint Already Exist By Name : endpoint2")
public void testUpdateApiEndpointWithAlreadyAvailableEndpointName() throws APIManagementException {
    /**
     * this test method verify the API Add with correct API object get invoked correctly
     */
    Endpoint endpoint1 = new Endpoint.Builder().id(UUID.randomUUID().toString()).endpointConfig("http://localhost").name("endpoint1").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
    Endpoint endpoint2 = new Endpoint.Builder().id(UUID.randomUUID().toString()).endpointConfig("http://localhost").name("endpoint2").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
    Endpoint endpoint3 = new Endpoint.Builder().id(UUID.randomUUID().toString()).endpointConfig("http://localhost").name("endpoint2").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
    Map<String, Endpoint> endpointMap = new HashMap<>();
    endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, endpoint1);
    endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, endpoint2);
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id(UUID.randomUUID().toString()).endpoint(endpointMap);
    apiBuilder.apiPermission("");
    apiBuilder.permissionMap(null);
    apiBuilder.policies(Collections.emptySet());
    apiBuilder.apiPolicy(null);
    ApiDAO apiDAO = Mockito.mock(ApiDAO.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);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway);
    Mockito.when(apiDAO.getEndpoint(endpoint1.getId())).thenReturn(endpoint1);
    Mockito.when(apiDAO.getEndpoint(endpoint2.getId())).thenReturn(endpoint2);
    Mockito.when(apiDAO.getEndpoint(endpoint3.getId())).thenReturn(null);
    Mockito.when(apiDAO.getEndpoint(endpoint1.getName())).thenReturn(endpoint1);
    Mockito.when(apiDAO.getEndpointByName(endpoint2.getName())).thenReturn(endpoint2);
    Map<String, Endpoint> updatedEndpointMap = new HashMap<>(endpointMap);
    updatedEndpointMap.replace(APIMgtConstants.SANDBOX_ENDPOINT, endpoint3);
    apiBuilder.endpoint(updatedEndpointMap);
    Mockito.when(apiDAO.getApiSwaggerDefinition(apiBuilder.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    apiPublisher.updateAPI(apiBuilder);
    Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(apiBuilder.getId(), apiBuilder.build());
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) HashMap(java.util.HashMap) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Example 85 with Endpoint

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

the class APIPublisherImplTestCase method testAddEndpointWhenNameEmpty.

@Test(description = "Add endpoint when endpoint name is empty")
public void testAddEndpointWhenNameEmpty() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, gatewaySourceGenerator, gateway);
    try {
        apiPublisher.addEndpoint(new Endpoint.Builder(SampleTestObjectCreator.createMockEndpoint()).name("").build());
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Endpoint name is not provided");
    }
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Aggregations

Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)118 Test (org.testng.annotations.Test)68 API (org.wso2.carbon.apimgt.core.models.API)58 HashMap (java.util.HashMap)55 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)50 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)46 ArrayList (java.util.ArrayList)38 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)33 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)30 Test (org.junit.Test)28 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)27 HashSet (java.util.HashSet)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)24 Map (java.util.Map)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 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)17