use of org.wso2.carbon.governance.api.endpoints.dataobjects.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");
}
use of org.wso2.carbon.governance.api.endpoints.dataobjects.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");
}
use of org.wso2.carbon.governance.api.endpoints.dataobjects.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);
}
}
use of org.wso2.carbon.governance.api.endpoints.dataobjects.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());
}
use of org.wso2.carbon.governance.api.endpoints.dataobjects.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");
}
}
Aggregations