@SuppressWarnings("unchecked") @Test public void test_Should_Create_TreatmentPlant() { final TreatmentPlantRequest treatmentPlantRequest = new TreatmentPlantRequest(); final RequestInfo requestInfo = new RequestInfo(); final User user = new User(); user.setId(1l); requestInfo.setUserInfo(user); treatmentPlantRequest.setRequestInfo(requestInfo); final List<TreatmentPlant> treatmentPlantList = new ArrayList<>(); final TreatmentPlant treatmentPlant = getTreatmentPlant(); treatmentPlantList.add(treatmentPlant); treatmentPlantRequest.setTreatmentPlants(treatmentPlantList); final TreatmentPlantRequest treatmentPlantReq = treatmentPlantRepository .create(treatmentPlantRequest); when(namedParameterJdbcTemplate.queryForObject(any(String.class), anyMap(), eq(Long.class))).thenReturn(2L); assertThat(treatmentPlantReq.getTreatmentPlants().size()).isEqualTo(1); }
public TreatmentPlantRequest create(final TreatmentPlantRequest treatmentPlantRequest) { log.info("treatmentPlantRequest::" + treatmentPlantRequest); final List<Map<String, Object>> batchArgs = new ArrayList<>(); final Map<String, Object> batchArguments = new HashMap<>(); final String treatmentPlantInsert = TreatmentPlantQueryBuilder.insertTreatmentPlantQuery(); final String storageReservoirQuery = TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(); for (final TreatmentPlant treatmentPlant : treatmentPlantRequest.getTreatmentPlants()) { Long storageReservoirId = null; try { batchArguments.put("name", treatmentPlant.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlant.getTenantId()); storageReservoirId = namedParameterJdbcTemplate.queryForObject(storageReservoirQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } batchArgs.add(new MapSqlParameterSource("id", Long.valueOf(treatmentPlant.getCode())) .addValue("code", treatmentPlant.getCode()).addValue("name", treatmentPlant.getName()) .addValue("planttype", treatmentPlant.getPlantType()) .addValue("location", treatmentPlant.getLocation()) .addValue("capacity", treatmentPlant.getCapacity()) .addValue("storagereservoirid", storageReservoirId) .addValue("description", treatmentPlant.getDescription()) .addValue("createdby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", treatmentPlant.getTenantId()).getValues()); } namedParameterJdbcTemplate.batchUpdate(treatmentPlantInsert, batchArgs.toArray(new Map[treatmentPlantRequest.getTreatmentPlants().size()])); return treatmentPlantRequest; }
TreatmentPlantRepository { public TreatmentPlantRequest create(final TreatmentPlantRequest treatmentPlantRequest) { log.info("treatmentPlantRequest::" + treatmentPlantRequest); final List<Map<String, Object>> batchArgs = new ArrayList<>(); final Map<String, Object> batchArguments = new HashMap<>(); final String treatmentPlantInsert = TreatmentPlantQueryBuilder.insertTreatmentPlantQuery(); final String storageReservoirQuery = TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(); for (final TreatmentPlant treatmentPlant : treatmentPlantRequest.getTreatmentPlants()) { Long storageReservoirId = null; try { batchArguments.put("name", treatmentPlant.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlant.getTenantId()); storageReservoirId = namedParameterJdbcTemplate.queryForObject(storageReservoirQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } batchArgs.add(new MapSqlParameterSource("id", Long.valueOf(treatmentPlant.getCode())) .addValue("code", treatmentPlant.getCode()).addValue("name", treatmentPlant.getName()) .addValue("planttype", treatmentPlant.getPlantType()) .addValue("location", treatmentPlant.getLocation()) .addValue("capacity", treatmentPlant.getCapacity()) .addValue("storagereservoirid", storageReservoirId) .addValue("description", treatmentPlant.getDescription()) .addValue("createdby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", treatmentPlant.getTenantId()).getValues()); } namedParameterJdbcTemplate.batchUpdate(treatmentPlantInsert, batchArgs.toArray(new Map[treatmentPlantRequest.getTreatmentPlants().size()])); return treatmentPlantRequest; } }
TreatmentPlantRepository { public TreatmentPlantRequest create(final TreatmentPlantRequest treatmentPlantRequest) { log.info("treatmentPlantRequest::" + treatmentPlantRequest); final List<Map<String, Object>> batchArgs = new ArrayList<>(); final Map<String, Object> batchArguments = new HashMap<>(); final String treatmentPlantInsert = TreatmentPlantQueryBuilder.insertTreatmentPlantQuery(); final String storageReservoirQuery = TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(); for (final TreatmentPlant treatmentPlant : treatmentPlantRequest.getTreatmentPlants()) { Long storageReservoirId = null; try { batchArguments.put("name", treatmentPlant.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlant.getTenantId()); storageReservoirId = namedParameterJdbcTemplate.queryForObject(storageReservoirQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } batchArgs.add(new MapSqlParameterSource("id", Long.valueOf(treatmentPlant.getCode())) .addValue("code", treatmentPlant.getCode()).addValue("name", treatmentPlant.getName()) .addValue("planttype", treatmentPlant.getPlantType()) .addValue("location", treatmentPlant.getLocation()) .addValue("capacity", treatmentPlant.getCapacity()) .addValue("storagereservoirid", storageReservoirId) .addValue("description", treatmentPlant.getDescription()) .addValue("createdby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", treatmentPlant.getTenantId()).getValues()); } namedParameterJdbcTemplate.batchUpdate(treatmentPlantInsert, batchArgs.toArray(new Map[treatmentPlantRequest.getTreatmentPlants().size()])); return treatmentPlantRequest; }  }
TreatmentPlantRepository { public TreatmentPlantRequest create(final TreatmentPlantRequest treatmentPlantRequest) { log.info("treatmentPlantRequest::" + treatmentPlantRequest); final List<Map<String, Object>> batchArgs = new ArrayList<>(); final Map<String, Object> batchArguments = new HashMap<>(); final String treatmentPlantInsert = TreatmentPlantQueryBuilder.insertTreatmentPlantQuery(); final String storageReservoirQuery = TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(); for (final TreatmentPlant treatmentPlant : treatmentPlantRequest.getTreatmentPlants()) { Long storageReservoirId = null; try { batchArguments.put("name", treatmentPlant.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlant.getTenantId()); storageReservoirId = namedParameterJdbcTemplate.queryForObject(storageReservoirQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } batchArgs.add(new MapSqlParameterSource("id", Long.valueOf(treatmentPlant.getCode())) .addValue("code", treatmentPlant.getCode()).addValue("name", treatmentPlant.getName()) .addValue("planttype", treatmentPlant.getPlantType()) .addValue("location", treatmentPlant.getLocation()) .addValue("capacity", treatmentPlant.getCapacity()) .addValue("storagereservoirid", storageReservoirId) .addValue("description", treatmentPlant.getDescription()) .addValue("createdby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", treatmentPlant.getTenantId()).getValues()); } namedParameterJdbcTemplate.batchUpdate(treatmentPlantInsert, batchArgs.toArray(new Map[treatmentPlantRequest.getTreatmentPlants().size()])); return treatmentPlantRequest; }  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 TreatmentPlantRequest create(final TreatmentPlantRequest treatmentPlantRequest) { log.info("treatmentPlantRequest::" + treatmentPlantRequest); final List<Map<String, Object>> batchArgs = new ArrayList<>(); final Map<String, Object> batchArguments = new HashMap<>(); final String treatmentPlantInsert = TreatmentPlantQueryBuilder.insertTreatmentPlantQuery(); final String storageReservoirQuery = TreatmentPlantQueryBuilder.getStorageReservoirIdQuery(); for (final TreatmentPlant treatmentPlant : treatmentPlantRequest.getTreatmentPlants()) { Long storageReservoirId = null; try { batchArguments.put("name", treatmentPlant.getStorageReservoirName()); batchArguments.put("tenantId", treatmentPlant.getTenantId()); storageReservoirId = namedParameterJdbcTemplate.queryForObject(storageReservoirQuery, batchArguments, Long.class); } catch (final EmptyResultDataAccessException e) { log.info("EmptyResultDataAccessException: Query returned empty result set"); } batchArgs.add(new MapSqlParameterSource("id", Long.valueOf(treatmentPlant.getCode())) .addValue("code", treatmentPlant.getCode()).addValue("name", treatmentPlant.getName()) .addValue("planttype", treatmentPlant.getPlantType()) .addValue("location", treatmentPlant.getLocation()) .addValue("capacity", treatmentPlant.getCapacity()) .addValue("storagereservoirid", storageReservoirId) .addValue("description", treatmentPlant.getDescription()) .addValue("createdby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("lastmodifiedby", Long.valueOf(treatmentPlantRequest.getRequestInfo().getUserInfo().getId())) .addValue("createddate", new Date(new java.util.Date().getTime())) .addValue("lastmodifieddate", new Date(new java.util.Date().getTime())) .addValue("tenantid", treatmentPlant.getTenantId()).getValues()); } namedParameterJdbcTemplate.batchUpdate(treatmentPlantInsert, batchArgs.toArray(new Map[treatmentPlantRequest.getTreatmentPlants().size()])); return treatmentPlantRequest; }  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);  }