@SuppressWarnings("unchecked") @Test public void test_Should_Search_TreatmentPlant() { final List<TreatmentPlant> treatmentPlantList = new ArrayList<>(); final TreatmentPlant treatmentPlant = getTreatmentPlant(); treatmentPlantList.add(treatmentPlant); when(namedParameterJdbcTemplate.queryForObject(any(String.class), anyMap(), eq(Long.class))).thenReturn(2L); when(namedParameterJdbcTemplate.query(any(String.class), anyMap(), any(TreatmentPlantRowMapper.class))) .thenReturn(treatmentPlantList); when(namedParameterJdbcTemplate.queryForObject(any(String.class), anyMap(), eq(String.class))) .thenReturn("abcd"); assertTrue(treatmentPlantRepository.findForCriteria(getTreatmentPlantGetRequest()).get(0) .getStorageReservoirName().equals("abcd")); }
public List<TreatmentPlant> findForCriteria(final TreatmentPlantGetRequest treatmentPlantGetRequest) { final Map<String, Object> batchArguments = new HashMap<>(); final Map<String, Object> batchArgs = new HashMap<>(); final Map<String, Object> preparedStatementValues = new HashMap<>(); try { if (treatmentPlantGetRequest.getStorageReservoirName() != null) { batchArguments.put("name", treatmentPlantGetRequest.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlantGetRequest.getTenantId()); final Long storageReservoirId = namedParameterJdbcTemplate.queryForObject( TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(), batchArguments, Long.class); treatmentPlantGetRequest.setStorageReservoirId(storageReservoirId); } } catch (final EmptyResultDataAccessException e) { log.error("EmptyResultDataAccessException: Query returned empty RS."); } final String queryStr = treatmentPlantQueryBuilder.getQuery(treatmentPlantGetRequest, preparedStatementValues); final List<TreatmentPlant> treatmentPlantList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, treatmentPlantRowMapper); final String storageReservoirNameOuery = TreatmentPlantQueryBuilder.getStorageReservoirName(); for (final TreatmentPlant treatmentPlant : treatmentPlantList) if (treatmentPlant.getStorageReservoirId() != null) { batchArgs.put("id", treatmentPlant.getStorageReservoirId()); batchArgs.put("tenantId", treatmentPlant.getTenantId()); treatmentPlant.setStorageReservoirName( namedParameterJdbcTemplate.queryForObject(storageReservoirNameOuery, batchArgs, String.class)); } return treatmentPlantList; }
TreatmentPlantRepository { public List<TreatmentPlant> findForCriteria(final TreatmentPlantGetRequest treatmentPlantGetRequest) { final Map<String, Object> batchArguments = new HashMap<>(); final Map<String, Object> batchArgs = new HashMap<>(); final Map<String, Object> preparedStatementValues = new HashMap<>(); try { if (treatmentPlantGetRequest.getStorageReservoirName() != null) { batchArguments.put("name", treatmentPlantGetRequest.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlantGetRequest.getTenantId()); final Long storageReservoirId = namedParameterJdbcTemplate.queryForObject( TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(), batchArguments, Long.class); treatmentPlantGetRequest.setStorageReservoirId(storageReservoirId); } } catch (final EmptyResultDataAccessException e) { log.error("EmptyResultDataAccessException: Query returned empty RS."); } final String queryStr = treatmentPlantQueryBuilder.getQuery(treatmentPlantGetRequest, preparedStatementValues); final List<TreatmentPlant> treatmentPlantList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, treatmentPlantRowMapper); final String storageReservoirNameOuery = TreatmentPlantQueryBuilder.getStorageReservoirName(); for (final TreatmentPlant treatmentPlant : treatmentPlantList) if (treatmentPlant.getStorageReservoirId() != null) { batchArgs.put("id", treatmentPlant.getStorageReservoirId()); batchArgs.put("tenantId", treatmentPlant.getTenantId()); treatmentPlant.setStorageReservoirName( namedParameterJdbcTemplate.queryForObject(storageReservoirNameOuery, batchArgs, String.class)); } return treatmentPlantList; } }
TreatmentPlantRepository { public List<TreatmentPlant> findForCriteria(final TreatmentPlantGetRequest treatmentPlantGetRequest) { final Map<String, Object> batchArguments = new HashMap<>(); final Map<String, Object> batchArgs = new HashMap<>(); final Map<String, Object> preparedStatementValues = new HashMap<>(); try { if (treatmentPlantGetRequest.getStorageReservoirName() != null) { batchArguments.put("name", treatmentPlantGetRequest.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlantGetRequest.getTenantId()); final Long storageReservoirId = namedParameterJdbcTemplate.queryForObject( TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(), batchArguments, Long.class); treatmentPlantGetRequest.setStorageReservoirId(storageReservoirId); } } catch (final EmptyResultDataAccessException e) { log.error("EmptyResultDataAccessException: Query returned empty RS."); } final String queryStr = treatmentPlantQueryBuilder.getQuery(treatmentPlantGetRequest, preparedStatementValues); final List<TreatmentPlant> treatmentPlantList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, treatmentPlantRowMapper); final String storageReservoirNameOuery = TreatmentPlantQueryBuilder.getStorageReservoirName(); for (final TreatmentPlant treatmentPlant : treatmentPlantList) if (treatmentPlant.getStorageReservoirId() != null) { batchArgs.put("id", treatmentPlant.getStorageReservoirId()); batchArgs.put("tenantId", treatmentPlant.getTenantId()); treatmentPlant.setStorageReservoirName( namedParameterJdbcTemplate.queryForObject(storageReservoirNameOuery, batchArgs, String.class)); } return treatmentPlantList; }  }
TreatmentPlantRepository { public List<TreatmentPlant> findForCriteria(final TreatmentPlantGetRequest treatmentPlantGetRequest) { final Map<String, Object> batchArguments = new HashMap<>(); final Map<String, Object> batchArgs = new HashMap<>(); final Map<String, Object> preparedStatementValues = new HashMap<>(); try { if (treatmentPlantGetRequest.getStorageReservoirName() != null) { batchArguments.put("name", treatmentPlantGetRequest.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlantGetRequest.getTenantId()); final Long storageReservoirId = namedParameterJdbcTemplate.queryForObject( TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(), batchArguments, Long.class); treatmentPlantGetRequest.setStorageReservoirId(storageReservoirId); } } catch (final EmptyResultDataAccessException e) { log.error("EmptyResultDataAccessException: Query returned empty RS."); } final String queryStr = treatmentPlantQueryBuilder.getQuery(treatmentPlantGetRequest, preparedStatementValues); final List<TreatmentPlant> treatmentPlantList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, treatmentPlantRowMapper); final String storageReservoirNameOuery = TreatmentPlantQueryBuilder.getStorageReservoirName(); for (final TreatmentPlant treatmentPlant : treatmentPlantList) if (treatmentPlant.getStorageReservoirId() != null) { batchArgs.put("id", treatmentPlant.getStorageReservoirId()); batchArgs.put("tenantId", treatmentPlant.getTenantId()); treatmentPlant.setStorageReservoirName( namedParameterJdbcTemplate.queryForObject(storageReservoirNameOuery, batchArgs, String.class)); } return treatmentPlantList; }  TreatmentPlantRequest create(final TreatmentPlantRequest treatmentPlantRequest); TreatmentPlantRequest update(final TreatmentPlantRequest treatmentPlantRequest); List<TreatmentPlant> findForCriteria(final TreatmentPlantGetRequest treatmentPlantGetRequest); boolean checkTreatmentPlantByNameAndCode(final String code, final String name, final String tenantId); boolean checkStorageReservoirExists(final String storageReservoirName, final String tenantId); }
TreatmentPlantRepository { public List<TreatmentPlant> findForCriteria(final TreatmentPlantGetRequest treatmentPlantGetRequest) { final Map<String, Object> batchArguments = new HashMap<>(); final Map<String, Object> batchArgs = new HashMap<>(); final Map<String, Object> preparedStatementValues = new HashMap<>(); try { if (treatmentPlantGetRequest.getStorageReservoirName() != null) { batchArguments.put("name", treatmentPlantGetRequest.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlantGetRequest.getTenantId()); final Long storageReservoirId = namedParameterJdbcTemplate.queryForObject( TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(), batchArguments, Long.class); treatmentPlantGetRequest.setStorageReservoirId(storageReservoirId); } } catch (final EmptyResultDataAccessException e) { log.error("EmptyResultDataAccessException: Query returned empty RS."); } final String queryStr = treatmentPlantQueryBuilder.getQuery(treatmentPlantGetRequest, preparedStatementValues); final List<TreatmentPlant> treatmentPlantList = namedParameterJdbcTemplate.query(queryStr, preparedStatementValues, treatmentPlantRowMapper); final String storageReservoirNameOuery = TreatmentPlantQueryBuilder.getStorageReservoirName(); for (final TreatmentPlant treatmentPlant : treatmentPlantList) if (treatmentPlant.getStorageReservoirId() != null) { batchArgs.put("id", treatmentPlant.getStorageReservoirId()); batchArgs.put("tenantId", treatmentPlant.getTenantId()); treatmentPlant.setStorageReservoirName( namedParameterJdbcTemplate.queryForObject(storageReservoirNameOuery, batchArgs, String.class)); } return treatmentPlantList; }  TreatmentPlantRequest create(final TreatmentPlantRequest treatmentPlantRequest); TreatmentPlantRequest update(final TreatmentPlantRequest treatmentPlantRequest); List<TreatmentPlant> findForCriteria(final TreatmentPlantGetRequest treatmentPlantGetRequest); boolean checkTreatmentPlantByNameAndCode(final String code, final String name, final String tenantId); boolean checkStorageReservoirExists(final String storageReservoirName, final String tenantId);  }