use of org.wso2.carbon.apimgt.keymgt.model.entity.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.keymgt.model.entity.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.keymgt.model.entity.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.keymgt.model.entity.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());
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Condition in project carbon-apimgt by wso2.
the class MappingUtil method fromBlockConditionListToListDTO.
/**
* Converts a List of Block Condition in to REST API LIST DTO Object.
*
* @param blockConditionList A List of Block Conditions
* @return REST API List DTO object derived from Block Condition list
*/
public static BlockingConditionListDTO fromBlockConditionListToListDTO(List<BlockConditions> blockConditionList) {
BlockingConditionListDTO listDTO = new BlockingConditionListDTO();
List<BlockingConditionDTO> blockingConditionDTOList = new ArrayList<>();
if (blockConditionList != null) {
for (BlockConditions blockCondition : blockConditionList) {
BlockingConditionDTO dto = fromBlockingConditionToDTO(blockCondition);
blockingConditionDTOList.add(dto);
}
}
listDTO.setCount(blockingConditionDTOList.size());
listDTO.setList(blockingConditionDTOList);
return listDTO;
}
Aggregations