use of org.wso2.carbon.apimgt.api.model.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testUpdateBlockCondition.
@Test
public void testUpdateBlockCondition() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
Mockito.when(apimgtDAO.updateBlockConditionState(1, "testState")).thenReturn(false, true);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
blockConditionsDTO.setConditionType("testType");
blockConditionsDTO.setConditionValue("USER");
PowerMockito.mockStatic(MultitenantUtils.class);
PowerMockito.when(MultitenantUtils.getTenantAwareUsername("User")).thenReturn("testValue");
Mockito.when(apimgtDAO.getBlockCondition(1)).thenReturn(blockConditionsDTO);
// updateState false
assertFalse(apiProvider.updateBlockCondition(1, "testState"));
// updateState true
assertTrue(apiProvider.updateBlockCondition(1, "testState"));
}
use of org.wso2.carbon.apimgt.api.model.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImpl method deleteBlockCondition.
@Override
public boolean deleteBlockCondition(int conditionId) throws APIManagementException {
BlockConditionsDTO blockCondition = apiMgtDAO.getBlockCondition(conditionId);
boolean deleteState = apiMgtDAO.deleteBlockCondition(conditionId);
if (deleteState && blockCondition != null) {
unpublishBlockCondition(blockCondition);
}
return deleteState;
}
use of org.wso2.carbon.apimgt.api.model.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImpl method updateBlockCondition.
@Override
public boolean updateBlockCondition(int conditionId, String state) throws APIManagementException {
boolean updateState = apiMgtDAO.updateBlockConditionState(conditionId, state);
BlockConditionsDTO blockConditionsDTO = apiMgtDAO.getBlockCondition(conditionId);
if (updateState) {
publishBlockingEventUpdate(blockConditionsDTO);
}
return updateState;
}
use of org.wso2.carbon.apimgt.api.model.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImpl method addBlockCondition.
@Override
public String addBlockCondition(String conditionType, String conditionValue) throws APIManagementException {
if (APIConstants.BLOCKING_CONDITIONS_USER.equals(conditionType)) {
conditionValue = MultitenantUtils.getTenantAwareUsername(conditionValue);
conditionValue = conditionValue + "@" + tenantDomain;
}
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
blockConditionsDTO.setConditionType(conditionType);
blockConditionsDTO.setConditionValue(conditionValue);
blockConditionsDTO.setTenantDomain(tenantDomain);
blockConditionsDTO.setEnabled(true);
blockConditionsDTO.setUUID(UUID.randomUUID().toString());
BlockConditionsDTO createdBlockConditionsDto = apiMgtDAO.addBlockConditions(blockConditionsDTO);
if (createdBlockConditionsDto != null) {
publishBlockingEvent(createdBlockConditionsDto, "true");
}
return createdBlockConditionsDto.getUUID();
}
use of org.wso2.carbon.apimgt.api.model.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIMgtDAOTest method testAddUpdateDeleteBlockCondition.
@Test
public void testAddUpdateDeleteBlockCondition() throws Exception {
Subscriber subscriber = new Subscriber("blockuser1");
subscriber.setTenantId(-1234);
subscriber.setEmail("abc@wso2.com");
subscriber.setSubscribedDate(new Date(System.currentTimeMillis()));
apiMgtDAO.addSubscriber(subscriber, null);
Policy applicationPolicy = getApplicationPolicy("testAddUpdateDeleteBlockCondition");
applicationPolicy.setTenantId(-1234);
apiMgtDAO.addApplicationPolicy((ApplicationPolicy) applicationPolicy);
Application application = new Application("testAddUpdateDeleteBlockCondition", subscriber);
application.setTier("testAddUpdateDeleteBlockCondition");
application.setId(apiMgtDAO.addApplication(application, "blockuser1", "testOrg"));
APIIdentifier apiId = new APIIdentifier("testAddUpdateDeleteBlockCondition", "testAddUpdateDeleteBlockCondition", "1.0.0");
API api = new API(apiId);
api.setContext("/testAddUpdateDeleteBlockCondition");
api.setContextTemplate("/testAddUpdateDeleteBlockCondition/{version}");
api.setVersionTimestamp(String.valueOf(System.currentTimeMillis()));
api.setUUID(UUID.randomUUID().toString());
apiMgtDAO.addAPI(api, -1234, "testOrg");
BlockConditionsDTO apiBlockConditionDto = new BlockConditionsDTO();
apiBlockConditionDto.setConditionValue("/testAddUpdateDeleteBlockCondition");
apiBlockConditionDto.setConditionType(APIConstants.BLOCKING_CONDITIONS_API);
apiBlockConditionDto.setUUID(UUID.randomUUID().toString());
apiBlockConditionDto.setTenantDomain("carbon.super");
BlockConditionsDTO apiUUID = apiMgtDAO.addBlockConditions(apiBlockConditionDto);
BlockConditionsDTO applicationBlockCondition = new BlockConditionsDTO();
applicationBlockCondition.setConditionValue("blockuser1:testAddUpdateDeleteBlockCondition");
applicationBlockCondition.setConditionType(APIConstants.BLOCKING_CONDITIONS_APPLICATION);
applicationBlockCondition.setUUID(UUID.randomUUID().toString());
applicationBlockCondition.setTenantDomain("carbon.super");
BlockConditionsDTO applicationUUID = apiMgtDAO.addBlockConditions(applicationBlockCondition);
assertNotNull(applicationUUID);
BlockConditionsDTO ipBlockcondition = new BlockConditionsDTO();
ipBlockcondition.setConditionValue("127.0.0.1");
ipBlockcondition.setConditionType(APIConstants.BLOCKING_CONDITIONS_IP);
ipBlockcondition.setUUID(UUID.randomUUID().toString());
ipBlockcondition.setTenantDomain("carbon.super");
BlockConditionsDTO ipUUID = apiMgtDAO.addBlockConditions(ipBlockcondition);
assertNotNull(ipUUID);
BlockConditionsDTO userBlockcondition = new BlockConditionsDTO();
userBlockcondition.setConditionValue("admin");
userBlockcondition.setConditionType(APIConstants.BLOCKING_CONDITIONS_USER);
userBlockcondition.setUUID(UUID.randomUUID().toString());
userBlockcondition.setTenantDomain("carbon.super");
BlockConditionsDTO userUUID = apiMgtDAO.addBlockConditions(userBlockcondition);
assertNotNull(apiMgtDAO.getBlockConditionByUUID(apiUUID.getUUID()));
assertNotNull(userUUID);
assertNotNull(apiMgtDAO.updateBlockConditionState(apiMgtDAO.getBlockConditionByUUID(userUUID.getUUID()).getConditionId(), "FALSE"));
assertNotNull(apiMgtDAO.updateBlockConditionStateByUUID(userUUID.getUUID(), "FALSE"));
apiMgtDAO.deleteBlockCondition(apiMgtDAO.getBlockConditionByUUID(userUUID.getUUID()).getConditionId());
apiMgtDAO.getBlockCondition(apiMgtDAO.getBlockConditionByUUID(ipUUID.getUUID()).getConditionId());
List<BlockConditionsDTO> blockConditions = apiMgtDAO.getBlockConditions("carbon.super");
for (BlockConditionsDTO blockConditionsDTO : blockConditions) {
apiMgtDAO.deleteBlockConditionByUUID(blockConditionsDTO.getUUID());
}
apiMgtDAO.deleteApplication(application);
apiMgtDAO.removeThrottlePolicy(PolicyConstants.POLICY_LEVEL_APP, applicationPolicy.getPolicyName(), -1234);
apiMgtDAO.deleteAPI(api.getUuid());
deleteSubscriber(subscriber.getId());
}
Aggregations