use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class BlockingConditionMappingUtilTestCase method fromBlockingConditionDTOToBlockConditionTest.
@Test(description = "From Blocking Condition DTO to Model")
public void fromBlockingConditionDTOToBlockConditionTest() throws Exception {
BlockingConditionDTO dto = new BlockingConditionDTO();
dto.setConditionId(UUID.randomUUID().toString());
dto.setConditionType(BLOCKING_CONDITION_IP_RANGE);
IPConditionDTO ipCondition = new IPConditionDTO();
ipCondition.setStartingIP("12.32.45.3");
ipCondition.setEndingIP("12.32.45.31");
dto.setIpCondition(ipCondition);
dto.setStatus(true);
BlockConditions conditions = BlockingConditionMappingUtil.fromBlockingConditionDTOToBlockCondition(dto);
Assert.assertNotNull(conditions);
Assert.assertEquals(BLOCKING_CONDITION_IP_RANGE, conditions.getConditionType());
Assert.assertEquals(conditions.getStartingIP(), dto.getIpCondition().getStartingIP());
Assert.assertEquals(conditions.getEndingIP(), dto.getIpCondition().getEndingIP());
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtilTestCase method fromQueryParamsConditionDtoToQueryParamsConditionModelTest.
@Test(description = "Convert Query param Condition DTO to QueryParamCondition Model object")
public void fromQueryParamsConditionDtoToQueryParamsConditionModelTest() throws Exception {
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setType(PolicyConstants.QUERY_PARAMS_CONDITION_TYPE);
QueryParameterConditionDTO queryParameterConditionDTO = new QueryParameterConditionDTO();
queryParameterConditionDTO.setParameterName("testParam");
queryParameterConditionDTO.setParameterValue("testParamValue");
throttleConditionDTO.setQueryParameterCondition(queryParameterConditionDTO);
QueryParameterCondition condition = (QueryParameterCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
Assert.assertNotNull(condition);
assertEquals(condition.getParameter(), "testParam");
assertEquals(condition.getValue(), "testParamValue");
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtilTestCase method fromHeaderConditionDtoToHeaderConditionModelTest.
@Test(description = "Convert Header Condition DTO to HeaderCondition Model object")
public void fromHeaderConditionDtoToHeaderConditionModelTest() throws Exception {
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setType(PolicyConstants.HEADER_CONDITION_TYPE);
HeaderConditionDTO headerConditionDTO = new HeaderConditionDTO();
headerConditionDTO.setHeaderName("testHeader");
headerConditionDTO.setHeaderValue("testHeaderValue");
throttleConditionDTO.setHeaderCondition(headerConditionDTO);
HeaderCondition condition = (HeaderCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
Assert.assertNotNull(condition);
assertEquals(condition.getHeaderName(), "testHeader");
assertEquals(condition.getValue(), "testHeaderValue");
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtilTestCase method fromIPRangeConditionDtoToIPConditionModelTest.
@Test(description = "Convert IP range IPCondition DTO to IPCondition Model object")
public void fromIPRangeConditionDtoToIPConditionModelTest() throws Exception {
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
IPConditionDTO ipConditionDTO = new IPConditionDTO();
ipConditionDTO.setIpConditionType(IP_RANGE_TYPE);
ipConditionDTO.setStartingIP("10.100.0.158");
ipConditionDTO.setEndingIP("10.100.0.178");
throttleConditionDTO.setIpCondition(ipConditionDTO);
IPCondition condition = (IPCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
Assert.assertNotNull(condition);
assertEquals(condition.getStartingIP(), "10.100.0.158");
assertEquals(condition.getEndingIP(), "10.100.0.178");
assertEquals(condition.getType(), IP_RANGE_TYPE);
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeleteBlockConditionByUuid.
@Test(description = "Test deleting block condition by uuid")
public void testDeleteBlockConditionByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
Mockito.when(policyDAO.deleteBlockConditionByUuid(blockConditions.getUuid())).thenReturn(true);
Boolean statusTrue = adminService.deleteBlockConditionByUuid(blockConditions.getUuid());
Assert.assertTrue(statusTrue);
// Error path
// Failure deleting
Mockito.when(policyDAO.deleteBlockConditionByUuid(blockConditions.getUuid())).thenReturn(false);
Boolean statusFalse = adminService.deleteBlockConditionByUuid(blockConditions.getUuid());
Assert.assertFalse(statusFalse);
// Error path
// APIMgtDAOException
Mockito.when(policyDAO.deleteBlockConditionByUuid(blockConditions.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.deleteBlockConditionByUuid(blockConditions.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't delete block condition with UUID: " + blockConditions.getUuid());
}
}
Aggregations