use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetAPIUsageByAPIId.
@Test
public void testGetAPIUsageByAPIId() throws APIManagementException, RegistryException, UserStoreException {
String uuid = UUID.randomUUID().toString();
SubscribedAPI subscribedAPI1 = new SubscribedAPI(new Subscriber("user1"), new APIIdentifier("admin", "API1", "1.0.0"));
SubscribedAPI subscribedAPI2 = new SubscribedAPI(new Subscriber("user1"), new APIIdentifier("admin", "API2", "1.0.0"));
UserApplicationAPIUsage apiResult1 = new UserApplicationAPIUsage();
apiResult1.addApiSubscriptions(subscribedAPI1);
apiResult1.addApiSubscriptions(subscribedAPI2);
SubscribedAPI subscribedAPI3 = new SubscribedAPI(new Subscriber("user2"), new APIIdentifier("admin", "API1", "1.0.0"));
SubscribedAPI subscribedAPI4 = new SubscribedAPI(new Subscriber("user2"), new APIIdentifier("admin", "API2", "1.0.0"));
UserApplicationAPIUsage apiResult2 = new UserApplicationAPIUsage();
apiResult2.addApiSubscriptions(subscribedAPI3);
apiResult2.addApiSubscriptions(subscribedAPI4);
UserApplicationAPIUsage[] apiResults = { apiResult1, apiResult2 };
Mockito.when(apimgtDAO.getAllAPIUsageByProviderAndApiId(uuid, "org1")).thenReturn(apiResults);
Mockito.when(apimgtDAO.getAPIIdentifierFromUUID(uuid)).thenReturn(new APIIdentifier("admin", "API1", "1.0.0"));
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
List<SubscribedAPI> subscribedAPIs = apiProvider.getAPIUsageByAPIId(uuid, "org1");
Assert.assertEquals(2, subscribedAPIs.size());
Assert.assertEquals("user1", subscribedAPIs.get(0).getSubscriber().getName());
Assert.assertEquals("user2", subscribedAPIs.get(1).getSubscriber().getName());
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testAddBlockCondition.
@Test
public void testAddBlockCondition() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
blockConditionsDTO.setUUID("12345");
Mockito.when(apimgtDAO.addBlockConditions(Mockito.any(BlockConditionsDTO.class))).thenReturn(blockConditionsDTO);
// condition type IP
assertEquals("12345", apiProvider.addBlockCondition("IP", "testValue"));
// condition type User
assertEquals("12345", apiProvider.addBlockCondition("USER", "testValue"));
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class ScopesApiServiceImpl method scopesGet.
public Response scopesGet(String xWSO2Tenant, String scopeKey, MessageContext messageContext) throws APIManagementException {
xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
ScopesDAO scopesDAO = ScopesDAO.getInstance();
if (StringUtils.isNotEmpty(xWSO2Tenant)) {
int tenantId = APIUtil.getTenantIdFromTenantDomain(xWSO2Tenant);
if (StringUtils.isNotEmpty(scopeKey)) {
List<Scope> model = new ArrayList<>();
Scope scope = scopesDAO.getScope(scopeKey, tenantId);
if (scope != null) {
model.add(scope);
}
return Response.ok().entity(SubscriptionValidationDataUtil.fromScopeListToScopeDtoList(model)).build();
} else {
return Response.ok().entity(SubscriptionValidationDataUtil.fromScopeListToScopeDtoList(scopesDAO.getScopes(tenantId))).build();
}
} else {
return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "X-WSo2-Tenant header is missing.").build();
}
}
Aggregations