@Test public void test_Inavalid_Find_MeterWaterRates() throws Exception { final Map<String, Object> preparedStatementValues = new HashMap<>(); final MeterWaterRatesGetRequest meterWaterRatesGetRequest = Mockito.mock(MeterWaterRatesGetRequest.class); final String queryString = "MyQuery"; when(meterWaterRatesQueryBuilder.getQuery(meterWaterRatesGetRequest, preparedStatementValues)).thenReturn(null); final List<MeterWaterRates> meterWaterRates = new ArrayList<>(); when(namedParameterJdbcTemplate.query(queryString, preparedStatementValues, meterWaterRatesRowMapper)) .thenReturn(null); assertTrue(meterWaterRates.equals(meterWaterRatesRepository.findForCriteria(meterWaterRatesGetRequest))); }
public List<MeterWaterRates> findForCriteria(final MeterWaterRatesGetRequest meterWaterRatesGetRequest) { if (meterWaterRatesGetRequest.getSourceTypeName() != null) { final Map<String, Object> paramMapForSourceType = new HashMap<>(); paramMapForSourceType.put("name", meterWaterRatesGetRequest.getSourceTypeName()); paramMapForSourceType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long sourceTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(), paramMapForSourceType, Long.class); meterWaterRatesGetRequest.setSourceTypeId(sourceTypeId); } if (meterWaterRatesGetRequest.getUsageTypeCode() != null) { final Map<String, Object> paramMapForUsageType = new HashMap<>(); paramMapForUsageType.put("code", meterWaterRatesGetRequest.getUsageTypeCode()); paramMapForUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long usageTypeId = namedParameterJdbcTemplate .queryForObject(MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForUsageType, Long.class); meterWaterRatesGetRequest.setUsageTypeId(String.valueOf(usageTypeId)); } if (meterWaterRatesGetRequest.getSubUsageTypeCode() != null) { final Map<String, Object> paramMapForSubUsageType = new HashMap<>(); paramMapForSubUsageType.put("code", meterWaterRatesGetRequest.getSubUsageTypeCode()); paramMapForSubUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long subUsageTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForSubUsageType, Long.class); meterWaterRatesGetRequest.setSubUsageTypeId(String.valueOf(subUsageTypeId)); } if (meterWaterRatesGetRequest.getPipeSize() != null) { final Map<String, Object> paramMapForPipeSize = new HashMap<>(); paramMapForPipeSize.put("sizeinmilimeter", meterWaterRatesGetRequest.getPipeSize()); paramMapForPipeSize.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long pipeSizeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(), paramMapForPipeSize, Long.class); meterWaterRatesGetRequest.setPipeSizeId(pipeSizeId); } final Map<String, Object> preparedStatementValues = new HashMap<>(); final String queryStr = meterWaterRatesQueryBuilder.getQuery(meterWaterRatesGetRequest, preparedStatementValues); final List<MeterWaterRates> meterWaterRatesList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, meterWaterRatesRowMapper); final String slabQuery = meterWaterRatesQueryBuilder.getSlabDetailsQuery(); final Map<String, Object> paramsForSlab = new HashMap<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) { paramsForSlab.put("meterwaterratesid", Long.valueOf(meterWaterRate.getCode())); paramsForSlab.put("tenantid", meterWaterRate.getTenantId()); final List<Slab> slabs = namedParameterJdbcTemplate.query(slabQuery, paramsForSlab, slabRowMapper); meterWaterRate.setSlab(slabs); } return meterWaterRatesList; }
MeterWaterRatesRepository { public List<MeterWaterRates> findForCriteria(final MeterWaterRatesGetRequest meterWaterRatesGetRequest) { if (meterWaterRatesGetRequest.getSourceTypeName() != null) { final Map<String, Object> paramMapForSourceType = new HashMap<>(); paramMapForSourceType.put("name", meterWaterRatesGetRequest.getSourceTypeName()); paramMapForSourceType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long sourceTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(), paramMapForSourceType, Long.class); meterWaterRatesGetRequest.setSourceTypeId(sourceTypeId); } if (meterWaterRatesGetRequest.getUsageTypeCode() != null) { final Map<String, Object> paramMapForUsageType = new HashMap<>(); paramMapForUsageType.put("code", meterWaterRatesGetRequest.getUsageTypeCode()); paramMapForUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long usageTypeId = namedParameterJdbcTemplate .queryForObject(MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForUsageType, Long.class); meterWaterRatesGetRequest.setUsageTypeId(String.valueOf(usageTypeId)); } if (meterWaterRatesGetRequest.getSubUsageTypeCode() != null) { final Map<String, Object> paramMapForSubUsageType = new HashMap<>(); paramMapForSubUsageType.put("code", meterWaterRatesGetRequest.getSubUsageTypeCode()); paramMapForSubUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long subUsageTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForSubUsageType, Long.class); meterWaterRatesGetRequest.setSubUsageTypeId(String.valueOf(subUsageTypeId)); } if (meterWaterRatesGetRequest.getPipeSize() != null) { final Map<String, Object> paramMapForPipeSize = new HashMap<>(); paramMapForPipeSize.put("sizeinmilimeter", meterWaterRatesGetRequest.getPipeSize()); paramMapForPipeSize.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long pipeSizeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(), paramMapForPipeSize, Long.class); meterWaterRatesGetRequest.setPipeSizeId(pipeSizeId); } final Map<String, Object> preparedStatementValues = new HashMap<>(); final String queryStr = meterWaterRatesQueryBuilder.getQuery(meterWaterRatesGetRequest, preparedStatementValues); final List<MeterWaterRates> meterWaterRatesList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, meterWaterRatesRowMapper); final String slabQuery = meterWaterRatesQueryBuilder.getSlabDetailsQuery(); final Map<String, Object> paramsForSlab = new HashMap<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) { paramsForSlab.put("meterwaterratesid", Long.valueOf(meterWaterRate.getCode())); paramsForSlab.put("tenantid", meterWaterRate.getTenantId()); final List<Slab> slabs = namedParameterJdbcTemplate.query(slabQuery, paramsForSlab, slabRowMapper); meterWaterRate.setSlab(slabs); } return meterWaterRatesList; } }
MeterWaterRatesRepository { public List<MeterWaterRates> findForCriteria(final MeterWaterRatesGetRequest meterWaterRatesGetRequest) { if (meterWaterRatesGetRequest.getSourceTypeName() != null) { final Map<String, Object> paramMapForSourceType = new HashMap<>(); paramMapForSourceType.put("name", meterWaterRatesGetRequest.getSourceTypeName()); paramMapForSourceType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long sourceTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(), paramMapForSourceType, Long.class); meterWaterRatesGetRequest.setSourceTypeId(sourceTypeId); } if (meterWaterRatesGetRequest.getUsageTypeCode() != null) { final Map<String, Object> paramMapForUsageType = new HashMap<>(); paramMapForUsageType.put("code", meterWaterRatesGetRequest.getUsageTypeCode()); paramMapForUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long usageTypeId = namedParameterJdbcTemplate .queryForObject(MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForUsageType, Long.class); meterWaterRatesGetRequest.setUsageTypeId(String.valueOf(usageTypeId)); } if (meterWaterRatesGetRequest.getSubUsageTypeCode() != null) { final Map<String, Object> paramMapForSubUsageType = new HashMap<>(); paramMapForSubUsageType.put("code", meterWaterRatesGetRequest.getSubUsageTypeCode()); paramMapForSubUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long subUsageTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForSubUsageType, Long.class); meterWaterRatesGetRequest.setSubUsageTypeId(String.valueOf(subUsageTypeId)); } if (meterWaterRatesGetRequest.getPipeSize() != null) { final Map<String, Object> paramMapForPipeSize = new HashMap<>(); paramMapForPipeSize.put("sizeinmilimeter", meterWaterRatesGetRequest.getPipeSize()); paramMapForPipeSize.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long pipeSizeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(), paramMapForPipeSize, Long.class); meterWaterRatesGetRequest.setPipeSizeId(pipeSizeId); } final Map<String, Object> preparedStatementValues = new HashMap<>(); final String queryStr = meterWaterRatesQueryBuilder.getQuery(meterWaterRatesGetRequest, preparedStatementValues); final List<MeterWaterRates> meterWaterRatesList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, meterWaterRatesRowMapper); final String slabQuery = meterWaterRatesQueryBuilder.getSlabDetailsQuery(); final Map<String, Object> paramsForSlab = new HashMap<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) { paramsForSlab.put("meterwaterratesid", Long.valueOf(meterWaterRate.getCode())); paramsForSlab.put("tenantid", meterWaterRate.getTenantId()); final List<Slab> slabs = namedParameterJdbcTemplate.query(slabQuery, paramsForSlab, slabRowMapper); meterWaterRate.setSlab(slabs); } return meterWaterRatesList; }  }
MeterWaterRatesRepository { public List<MeterWaterRates> findForCriteria(final MeterWaterRatesGetRequest meterWaterRatesGetRequest) { if (meterWaterRatesGetRequest.getSourceTypeName() != null) { final Map<String, Object> paramMapForSourceType = new HashMap<>(); paramMapForSourceType.put("name", meterWaterRatesGetRequest.getSourceTypeName()); paramMapForSourceType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long sourceTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(), paramMapForSourceType, Long.class); meterWaterRatesGetRequest.setSourceTypeId(sourceTypeId); } if (meterWaterRatesGetRequest.getUsageTypeCode() != null) { final Map<String, Object> paramMapForUsageType = new HashMap<>(); paramMapForUsageType.put("code", meterWaterRatesGetRequest.getUsageTypeCode()); paramMapForUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long usageTypeId = namedParameterJdbcTemplate .queryForObject(MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForUsageType, Long.class); meterWaterRatesGetRequest.setUsageTypeId(String.valueOf(usageTypeId)); } if (meterWaterRatesGetRequest.getSubUsageTypeCode() != null) { final Map<String, Object> paramMapForSubUsageType = new HashMap<>(); paramMapForSubUsageType.put("code", meterWaterRatesGetRequest.getSubUsageTypeCode()); paramMapForSubUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long subUsageTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForSubUsageType, Long.class); meterWaterRatesGetRequest.setSubUsageTypeId(String.valueOf(subUsageTypeId)); } if (meterWaterRatesGetRequest.getPipeSize() != null) { final Map<String, Object> paramMapForPipeSize = new HashMap<>(); paramMapForPipeSize.put("sizeinmilimeter", meterWaterRatesGetRequest.getPipeSize()); paramMapForPipeSize.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long pipeSizeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(), paramMapForPipeSize, Long.class); meterWaterRatesGetRequest.setPipeSizeId(pipeSizeId); } final Map<String, Object> preparedStatementValues = new HashMap<>(); final String queryStr = meterWaterRatesQueryBuilder.getQuery(meterWaterRatesGetRequest, preparedStatementValues); final List<MeterWaterRates> meterWaterRatesList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, meterWaterRatesRowMapper); final String slabQuery = meterWaterRatesQueryBuilder.getSlabDetailsQuery(); final Map<String, Object> paramsForSlab = new HashMap<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) { paramsForSlab.put("meterwaterratesid", Long.valueOf(meterWaterRate.getCode())); paramsForSlab.put("tenantid", meterWaterRate.getTenantId()); final List<Slab> slabs = namedParameterJdbcTemplate.query(slabQuery, paramsForSlab, slabRowMapper); meterWaterRate.setSlab(slabs); } return meterWaterRatesList; }  MeterWaterRatesRequest create(final MeterWaterRatesRequest meterWaterRatesRequest); MeterWaterRatesRequest update(final MeterWaterRatesRequest meterWaterRatesRequest); List<MeterWaterRates> findForCriteria(final MeterWaterRatesGetRequest meterWaterRatesGetRequest); boolean checkMeterWaterRatesExists(final String code, final Long usageTypeId, final Long subUsageTypeId,
            final String sourceTypeName, final Double pipeSize, final String tenantId); boolean checkPipeSizeExists(final Double pipeSize, final String tenantId); boolean checkSourceTypeExists(final String sourceTypeName, final String tenantId); Map<String, Object> checkUsageAndSubUsageTypeExists(final String usageType, final String tenantId); }
MeterWaterRatesRepository { public List<MeterWaterRates> findForCriteria(final MeterWaterRatesGetRequest meterWaterRatesGetRequest) { if (meterWaterRatesGetRequest.getSourceTypeName() != null) { final Map<String, Object> paramMapForSourceType = new HashMap<>(); paramMapForSourceType.put("name", meterWaterRatesGetRequest.getSourceTypeName()); paramMapForSourceType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long sourceTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getSourceTypeIdQueryForSearch(), paramMapForSourceType, Long.class); meterWaterRatesGetRequest.setSourceTypeId(sourceTypeId); } if (meterWaterRatesGetRequest.getUsageTypeCode() != null) { final Map<String, Object> paramMapForUsageType = new HashMap<>(); paramMapForUsageType.put("code", meterWaterRatesGetRequest.getUsageTypeCode()); paramMapForUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long usageTypeId = namedParameterJdbcTemplate .queryForObject(MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForUsageType, Long.class); meterWaterRatesGetRequest.setUsageTypeId(String.valueOf(usageTypeId)); } if (meterWaterRatesGetRequest.getSubUsageTypeCode() != null) { final Map<String, Object> paramMapForSubUsageType = new HashMap<>(); paramMapForSubUsageType.put("code", meterWaterRatesGetRequest.getSubUsageTypeCode()); paramMapForSubUsageType.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long subUsageTypeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getUsageTypeIdQueryForSearch(), paramMapForSubUsageType, Long.class); meterWaterRatesGetRequest.setSubUsageTypeId(String.valueOf(subUsageTypeId)); } if (meterWaterRatesGetRequest.getPipeSize() != null) { final Map<String, Object> paramMapForPipeSize = new HashMap<>(); paramMapForPipeSize.put("sizeinmilimeter", meterWaterRatesGetRequest.getPipeSize()); paramMapForPipeSize.put("tenantId", meterWaterRatesGetRequest.getTenantId()); final Long pipeSizeId = namedParameterJdbcTemplate.queryForObject( MeterWaterRatesQueryBuilder.getPipeSizeIdQueryForSearch(), paramMapForPipeSize, Long.class); meterWaterRatesGetRequest.setPipeSizeId(pipeSizeId); } final Map<String, Object> preparedStatementValues = new HashMap<>(); final String queryStr = meterWaterRatesQueryBuilder.getQuery(meterWaterRatesGetRequest, preparedStatementValues); final List<MeterWaterRates> meterWaterRatesList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, meterWaterRatesRowMapper); final String slabQuery = meterWaterRatesQueryBuilder.getSlabDetailsQuery(); final Map<String, Object> paramsForSlab = new HashMap<>(meterWaterRatesList.size()); for (final MeterWaterRates meterWaterRate : meterWaterRatesList) { paramsForSlab.put("meterwaterratesid", Long.valueOf(meterWaterRate.getCode())); paramsForSlab.put("tenantid", meterWaterRate.getTenantId()); final List<Slab> slabs = namedParameterJdbcTemplate.query(slabQuery, paramsForSlab, slabRowMapper); meterWaterRate.setSlab(slabs); } return meterWaterRatesList; }  MeterWaterRatesRequest create(final MeterWaterRatesRequest meterWaterRatesRequest); MeterWaterRatesRequest update(final MeterWaterRatesRequest meterWaterRatesRequest); List<MeterWaterRates> findForCriteria(final MeterWaterRatesGetRequest meterWaterRatesGetRequest); boolean checkMeterWaterRatesExists(final String code, final Long usageTypeId, final Long subUsageTypeId,
            final String sourceTypeName, final Double pipeSize, final String tenantId); boolean checkPipeSizeExists(final Double pipeSize, final String tenantId); boolean checkSourceTypeExists(final String sourceTypeName, final String tenantId); Map<String, Object> checkUsageAndSubUsageTypeExists(final String usageType, final String tenantId);  }