Search in sources :

Example 36 with Condition

use of org.wso2.carbon.apimgt.api.model.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");
}
Also used : QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) Test(org.testng.annotations.Test)

Example 37 with Condition

use of org.wso2.carbon.apimgt.api.model.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");
}
Also used : HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) Test(org.testng.annotations.Test)

Example 38 with Condition

use of org.wso2.carbon.apimgt.api.model.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);
}
Also used : IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) Test(org.testng.annotations.Test)

Example 39 with Condition

use of org.wso2.carbon.apimgt.api.model.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());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 40 with Condition

use of org.wso2.carbon.apimgt.api.model.policy.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;
}
Also used : BlockingConditionListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) ArrayList(java.util.ArrayList) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO)

Aggregations

HashMap (java.util.HashMap)39 Test (org.junit.Test)32 Test (org.testng.annotations.Test)31 ArrayList (java.util.ArrayList)30 List (java.util.List)26 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)26 ConditionDto (org.wso2.carbon.apimgt.impl.dto.ConditionDto)26 MessageContext (org.apache.synapse.MessageContext)25 PreparedStatement (java.sql.PreparedStatement)23 Map (java.util.Map)22 ResultSet (java.sql.ResultSet)20 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)18 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)18 Connection (java.sql.Connection)16 SQLException (java.sql.SQLException)16 TreeMap (java.util.TreeMap)16 HeaderCondition (org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)15 JWTClaimsCondition (org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition)15 QueryParameterCondition (org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)15 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)15