use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class ApiMgtDAO method getSubscriptionBlockCondition.
/**
* Get details of the subscription block condition by condition value and tenant domain
*
* @param conditionValue condition value of the block condition
* @param tenantDomain tenant domain of the block condition
* @return Block condition
* @throws APIManagementException
*/
public BlockConditionsDTO getSubscriptionBlockCondition(String conditionValue, String tenantDomain) throws APIManagementException {
Connection connection = null;
PreparedStatement selectPreparedStatement = null;
ResultSet resultSet = null;
BlockConditionsDTO blockCondition = null;
try {
String query = SQLConstants.ThrottleSQLConstants.GET_SUBSCRIPTION_BLOCK_CONDITION_BY_VALUE_AND_DOMAIN_SQL;
connection = APIMgtDBUtil.getConnection();
connection.setAutoCommit(true);
selectPreparedStatement = connection.prepareStatement(query);
selectPreparedStatement.setString(1, conditionValue);
selectPreparedStatement.setString(2, tenantDomain);
resultSet = selectPreparedStatement.executeQuery();
if (resultSet.next()) {
blockCondition = new BlockConditionsDTO();
blockCondition.setEnabled(resultSet.getBoolean("ENABLED"));
blockCondition.setConditionType(resultSet.getString("TYPE"));
blockCondition.setConditionValue(resultSet.getString("BLOCK_CONDITION"));
blockCondition.setConditionId(resultSet.getInt("CONDITION_ID"));
blockCondition.setTenantDomain(resultSet.getString("DOMAIN"));
blockCondition.setUUID(resultSet.getString("UUID"));
}
} catch (SQLException e) {
if (connection != null) {
try {
connection.rollback();
} catch (SQLException ex) {
handleException("Failed to rollback getting Subscription Block condition with condition value " + conditionValue + " of tenant " + tenantDomain, ex);
}
}
handleException("Failed to get Subscription Block condition with condition value " + conditionValue + " of tenant " + tenantDomain, e);
} finally {
APIMgtDBUtil.closeAllConnections(selectPreparedStatement, connection, resultSet);
}
return blockCondition;
}
use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class ApiMgtDAO method getBlockCondition.
/**
* Get details of a block condition by Id
*
* @param conditionId id of the condition
* @return Block conditoin represented by the UUID
* @throws APIManagementException
*/
public BlockConditionsDTO getBlockCondition(int conditionId) throws APIManagementException {
Connection connection = null;
PreparedStatement selectPreparedStatement = null;
ResultSet resultSet = null;
BlockConditionsDTO blockCondition = null;
try {
String query = SQLConstants.ThrottleSQLConstants.GET_BLOCK_CONDITION_SQL;
connection = APIMgtDBUtil.getConnection();
connection.setAutoCommit(true);
selectPreparedStatement = connection.prepareStatement(query);
selectPreparedStatement.setInt(1, conditionId);
resultSet = selectPreparedStatement.executeQuery();
if (resultSet.next()) {
blockCondition = new BlockConditionsDTO();
blockCondition.setEnabled(resultSet.getBoolean("ENABLED"));
blockCondition.setConditionType(resultSet.getString("TYPE"));
blockCondition.setConditionValue(resultSet.getString("BLOCK_CONDITION"));
blockCondition.setConditionId(conditionId);
blockCondition.setTenantDomain(resultSet.getString("DOMAIN"));
blockCondition.setUUID(resultSet.getString("UUID"));
}
} catch (SQLException e) {
if (connection != null) {
try {
connection.rollback();
} catch (SQLException ex) {
handleException("Failed to rollback getting Block condition with id " + conditionId, ex);
}
}
handleException("Failed to get Block condition with id " + conditionId, e);
} finally {
APIMgtDBUtil.closeAllConnections(selectPreparedStatement, connection, resultSet);
}
return blockCondition;
}
use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testDeleteBlockCondition.
@Test
public void testDeleteBlockCondition() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
Mockito.when(apimgtDAO.getBlockCondition(1111)).thenReturn(blockConditionsDTO);
Mockito.when(apimgtDAO.deleteBlockCondition(1111)).thenReturn(false, true);
// deleteState false
assertFalse(apiProvider.deleteBlockCondition(1111));
// deleteState true
assertTrue(apiProvider.deleteBlockCondition(1111));
}
use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testDeleteBlockConditionByUUID.
@Test
public void testDeleteBlockConditionByUUID() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
blockConditionsDTO.setConditionType("testType");
blockConditionsDTO.setConditionValue("USER");
blockConditionsDTO.setConditionId(1111);
Mockito.when(apimgtDAO.getBlockConditionByUUID("testId")).thenReturn(blockConditionsDTO);
Mockito.when(apimgtDAO.deleteBlockCondition(1111)).thenReturn(false, true);
PowerMockito.mockStatic(MultitenantUtils.class);
PowerMockito.when(MultitenantUtils.getTenantAwareUsername("User")).thenReturn("testValue");
// deleteState false
assertFalse(apiProvider.deleteBlockConditionByUUID("testId"));
// deleteState true
assertTrue(apiProvider.deleteBlockConditionByUUID("testId"));
}
use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetBlockCondition.
@Test
public void testGetBlockCondition() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
Mockito.when(apimgtDAO.getBlockCondition(Mockito.anyInt())).thenReturn(blockConditionsDTO);
assertNotNull(apiProvider.getBlockCondition(Mockito.anyInt()));
}
Aggregations