use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testUpdateRating.
@Test
public void testUpdateRating() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Rating rating1 = SampleTestObjectCreator.createDefaultRating(api.getId());
apiDAO.addRating(api.getId(), rating1);
Rating rating2 = SampleTestObjectCreator.createDefaultRating(api.getId());
rating2.setRating(4);
apiDAO.updateRating(api.getId(), rating1.getUuid(), rating2);
Rating ratingFromDB = apiDAO.getRatingByUUID(api.getId(), rating1.getUuid());
Assert.assertNotNull(ratingFromDB);
Assert.assertEquals(4, ratingFromDB.getRating());
}
use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddGetComment.
@Test
public void testAddGetComment() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
apiDAO.addComment(comment, api.getId());
Comment commentFromDB = apiDAO.getCommentByUUID(comment.getUuid(), api.getId());
Assert.assertNotNull(commentFromDB);
}
use of org.wso2.carbon.apimgt.api.APIDefinition 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);
}
use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testCreateNewAPIVersionWithEmptyAPIDefinition.
@Test(description = "Create new API version when API definition is empty")
public void testCreateNewAPIVersionWithEmptyAPIDefinition() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
API api = SampleTestObjectCreator.createDefaultAPI().apiDefinition("").build();
String uuid = api.getId();
APIGateway gateway = Mockito.mock(APIGateway.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiSubscriptionDAO, apiLifecycleManager, gateway);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsByAPI(api.getId())).thenReturn(new ArrayList<>());
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
String newUUid = apiPublisher.createNewAPIVersion(uuid, "2.0.0");
Mockito.verify(apiDAO, Mockito.times(1)).getAPI(uuid);
Mockito.verify(apiDAO, Mockito.times(0)).addAPI(api);
Assert.assertNotEquals(uuid, newUUid);
}
use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultAPI.
public static API.APIBuilder createDefaultAPI() {
Set<String> transport = new HashSet<>();
transport.add(HTTP);
transport.add(HTTPS);
Set<String> tags = new HashSet<>();
tags.add(TAG_CLIMATE);
Set<Policy> policies = new HashSet<>();
policies.add(goldSubscriptionPolicy);
policies.add(silverSubscriptionPolicy);
policies.add(bronzeSubscriptionPolicy);
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner(NAME_BUSINESS_OWNER_1);
businessInformation.setBusinessOwnerEmail(EMAIL_BUSINESS_OWNER_1);
businessInformation.setTechnicalOwner(NAME_TECHNICAL_OWNER_1);
businessInformation.setTechnicalOwnerEmail(EMAIL_TECHNICAL_OWNER_1);
String permissionJson = "[{\"groupId\" : \"developer\", \"permission\" : " + "[\"READ\",\"UPDATE\"]},{\"groupId\" : \"admin\", \"permission\" : [\"READ\",\"UPDATE\"," + "\"DELETE\", \"MANAGE_SUBSCRIPTION\"]}]";
Set<String> visibleRoles = new HashSet<>();
visibleRoles.add("testRple");
List<String> labels = new ArrayList<>();
labels.add("testLabel");
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList(APIMgtConstants.FunctionsConstants.GET, APIMgtConstants.FunctionsConstants.POST, APIMgtConstants.FunctionsConstants.DELETE));
corsConfiguration.setAllowHeaders(Arrays.asList(ALLOWED_HEADER_AUTHORIZATION, ALLOWED_HEADER_CUSTOM));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Arrays.asList("*"));
Map<String, Endpoint> endpointMap = new HashMap<>();
endpointMap.put("TestEndpoint", createMockEndpoint());
API.APIBuilder apiBuilder = new API.APIBuilder(ADMIN, "WeatherAPI", API_VERSION).id(UUID.randomUUID().toString()).context("weather").description("Get Weather Info").lifeCycleStatus(APIStatus.CREATED.getStatus()).lifecycleInstanceId(UUID.randomUUID().toString()).endpoint(Collections.emptyMap()).wsdlUri("http://localhost:9443/echo?wsdl").isResponseCachingEnabled(false).cacheTimeout(60).isDefaultVersion(false).apiPolicy(unlimitedApiPolicy).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.PUBLIC).visibleRoles(visibleRoles).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy(ADMIN).updatedBy(ADMIN).lastUpdatedTime(LocalDateTime.now()).apiPermission(permissionJson).uriTemplates(getMockUriTemplates()).apiDefinition(apiDefinition).workflowStatus(WORKFLOW_STATUS).labels(labels).endpoint(endpointMap);
Map map = new HashMap();
map.put(DEVELOPER_ROLE_ID, 6);
map.put(ADMIN_ROLE_ID, 15);
apiBuilder.permissionMap(map);
return apiBuilder;
}
Aggregations