use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAttributeSearchAPIsStore.
@Test
public void testAttributeSearchAPIsStore() throws Exception {
// Add few APIs with different attributes.
List<String> apiIDList = createAPIsAndGetIDsOfAddedAPIs();
List<String> userRoles = new ArrayList<>();
Map<String, String> attributeMap = new HashMap<>();
String[] expectedAPINames;
// Asserting results for different search queries
// Attribute search for "provider", for "admin" role
userRoles.add(ADMIN);
attributeMap.put("provider", "a");
expectedAPINames = new String[] { "PublicAPI", "AdminManagerAPI" };
Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
userRoles.clear();
attributeMap.clear();
// Attribute search for "version", for "manager" role
userRoles.add(MANAGER_ROLE);
attributeMap.put("version", "2.3");
expectedAPINames = new String[] { "PublicAPI", "ManagerOnlyAPI" };
Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
userRoles.clear();
attributeMap.clear();
// Attribute search for "context", for "manager", "employee" and "customer" roles
userRoles.add(MANAGER_ROLE);
userRoles.add(EMPLOYEE_ROLE);
userRoles.add(CUSTOMER_ROLE);
attributeMap.put("context", "Man");
expectedAPINames = new String[] { "ManagerOnlyAPI", "AdminManagerAPI" };
Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
userRoles.clear();
attributeMap.clear();
// Attribute search for "description", for "admin" role
userRoles.add(ADMIN);
attributeMap.put("description", "Admin and manager");
expectedAPINames = new String[] { "AdminManagerAPI" };
Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
userRoles.clear();
attributeMap.clear();
// Attribute search for "tags", for "manager", "employee" and "customer" roles
userRoles.add(MANAGER_ROLE);
userRoles.add(EMPLOYEE_ROLE);
userRoles.add(CUSTOMER_ROLE);
attributeMap.put("tags", "E");
expectedAPINames = new String[] { "ManagerOnlyAPI", "NonAdminAPI" };
Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
userRoles.clear();
attributeMap.clear();
// Attribute search for "subcontext", for "manager", "employee" and "customer" roles
userRoles.add(MANAGER_ROLE);
userRoles.add(EMPLOYEE_ROLE);
userRoles.add(CUSTOMER_ROLE);
attributeMap.put("subcontext", "C");
expectedAPINames = new String[] { "AdminManagerAPI", "EmployeeAPI", "NonAdminAPI" };
Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
userRoles.clear();
attributeMap.clear();
// cleanup added APIs
ApiDAO apiDAO = DAOFactory.getApiDAO();
for (String apiID : apiIDList) {
apiDAO.deleteAPI(apiID);
}
}
use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testSearchAPIs.
@Test
public void testSearchAPIs() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
Set<String> userRoles = new HashSet<>(Arrays.asList(CUSTOMER_ROLE, MANAGER_ROLE, EMPLOYEE_ROLE));
// Sample API names
final String mixedCaseString = "Mixed Case";
final String lowerCaseString = "lower case";
final String upperCaseString = "UPPER CASE";
final String charSymbolNumString = "mi ##symbol 12num";
final String symbolSpaceString = "_under & Score_";
// Search string cases
final String commonMixedCaseSearchString = "CaSe";
final String commonLowerCaseSearchString = "case";
final String commonUpperCaseSearchString = "CASE";
final String symbolSearchString = "##symbol";
// In some databases numbers are not used in indexing
final String numberSearchString = "12n";
// API Provider, the person who owns the API
final String provider = "John";
// Create test data
Map<String, API> apis = new HashMap<>();
apis.put(mixedCaseString, SampleTestObjectCreator.createUniqueAPI().name(mixedCaseString).provider(provider).build());
apis.put(lowerCaseString, SampleTestObjectCreator.createUniqueAPI().name(lowerCaseString).provider(provider).build());
apis.put(upperCaseString, SampleTestObjectCreator.createUniqueAPI().name(upperCaseString).provider(provider).build());
apis.put(charSymbolNumString, SampleTestObjectCreator.createUniqueAPI().name(charSymbolNumString).provider(provider).build());
apis.put(symbolSpaceString, SampleTestObjectCreator.createUniqueAPI().name(symbolSpaceString).provider(provider).build());
// Add APIs
testAddGetEndpoint();
for (Map.Entry<String, API> entry : apis.entrySet()) {
API api = entry.getValue();
apiDAO.addAPI(api);
// Replace with summary object for validation
apis.put(entry.getKey(), SampleTestObjectCreator.getSummaryFromAPI(api));
}
// Sleep for indexing
Thread.sleep(5000);
// Expected common string formatApiSearch result
List<API> commonStringResult = new ArrayList<>();
commonStringResult.add(apis.get(mixedCaseString));
commonStringResult.add(apis.get(lowerCaseString));
commonStringResult.add(apis.get(upperCaseString));
// Search by common mixed case
List<API> apiList = apiDAO.searchAPIs(new HashSet<>(), provider, commonMixedCaseSearchString, 0, 10);
Assert.assertEquals(apiList.size(), 3);
Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(apiList, commonStringResult, new APIComparator()), TestUtil.printListDiff(apiList, commonStringResult));
// Search by common lower case
apiList = apiDAO.searchAPIs(userRoles, provider, commonLowerCaseSearchString, 0, 10);
Assert.assertEquals(apiList.size(), 3);
Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(apiList, commonStringResult, new APIComparator()), TestUtil.printListDiff(apiList, commonStringResult));
// Search by common upper case
apiList = apiDAO.searchAPIs(userRoles, provider, commonUpperCaseSearchString, 0, 10);
Assert.assertEquals(apiList.size(), 3);
Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(apiList, commonStringResult, new APIComparator()), TestUtil.printListDiff(apiList, commonStringResult));
// Search by symbol
apiList = apiDAO.searchAPIs(userRoles, provider, symbolSearchString, 0, 10);
Assert.assertEquals(apiList.size(), 1);
API actualAPI = apiList.get(0);
API expectedAPI = apis.get(charSymbolNumString);
Assert.assertEquals(actualAPI, expectedAPI, TestUtil.printDiff(actualAPI, expectedAPI));
// Search by number
apiList = apiDAO.searchAPIs(userRoles, provider, numberSearchString, 0, 10);
Assert.assertEquals(apiList.size(), 1);
actualAPI = apiList.get(0);
expectedAPI = apis.get(charSymbolNumString);
Assert.assertEquals(actualAPI, expectedAPI, TestUtil.printDiff(actualAPI, expectedAPI));
}
use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetAPIsWhenUserIsProvider.
@Test(description = "Tests getting the APIs when the user is the provider of the API")
public void testGetAPIsWhenUserIsProvider() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
Set<String> rolesOfUser = new HashSet<>();
// The ID here is the group ID of the provider of the API. This ID is not assigned permissions for the API
rolesOfUser.add(ALTERNATIVE_USER_ROLE_ID);
// But this user is the provider of the API
List<API> apiList = apiDAO.getAPIs(rolesOfUser, ADMIN);
Assert.assertTrue(apiList.isEmpty());
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api1 = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api1);
apiList = apiDAO.getAPIs(rolesOfUser, ADMIN);
List<API> expectedAPIs = new ArrayList<>();
expectedAPIs.add(SampleTestObjectCreator.copyAPISummary(api1));
// The provider will have all permissions for the API by default
Assert.assertTrue(apiList.size() == 1);
Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(apiList, expectedAPIs, new APIComparator()), TestUtil.printDiff(apiList, expectedAPIs));
}
use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetSubscribersOfProviderException.
@Test(description = "Exception when getting subscriptions for a provider's APIs", expectedExceptions = APIManagementException.class)
public void testGetSubscribersOfProviderException() throws APIManagementException {
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiSubscriptionDAO);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsForUser(1, 2, USER)).thenThrow(new APIMgtDAOException("Unable to fetch subscriptions APIs of provider " + USER));
apiPublisher.getSubscribersOfProvider(1, 2, USER);
}
use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class APIImportExportTestCase method createApi.
private static API.APIBuilder createApi(String provider, String apiId, String name, String version, String description, Map<String, Endpoint> endpointTypeToIdMap) throws APIManagementException {
Set<String> transport = new HashSet<>();
transport.add("http");
Set<Policy> policies = new HashSet<>();
policies.add(new SubscriptionPolicy("Silver"));
policies.add(new SubscriptionPolicy("Bronze"));
Set<String> tags = new HashSet<>();
tags.add("food");
tags.add("beverage");
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner("John Doe");
businessInformation.setBusinessOwnerEmail("john.doe@annonymous.com");
businessInformation.setTechnicalOwner("Jane Doe");
businessInformation.setBusinessOwnerEmail("jane.doe@annonymous.com");
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList("GET", "POST", "DELETE"));
corsConfiguration.setAllowHeaders(Arrays.asList("Authorization", "X-Custom"));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Collections.singletonList("*"));
API.APIBuilder apiBuilder = new API.APIBuilder(provider, name, version).id(apiId).context(UUID.randomUUID().toString()).description(description).lifeCycleStatus("CREATED").apiDefinition(api1Definition).wsdlUri("http://www.webservicex.net/globalweather.asmx?op=GetWeather?wsdl").isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(new APIPolicy("Gold")).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList("customer", "manager", "employee"))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy("Adam Doe").lastUpdatedTime(LocalDateTime.now()).endpoint(endpointTypeToIdMap);
apiBuilder.uriTemplates(Collections.emptyMap());
return apiBuilder;
}
Aggregations