@Test public void getRegistrationTest() throws URISyntaxException, RegistrationPersistenceException, EmptyResultDataAccessException { RegisterContext registerContext = createRegisterContextTemperature(); registerContext.setRegistrationId("12345"); Instant expirationDate = Instant.now().plus(1, ChronoUnit.DAYS); Registration registration = new Registration(expirationDate, registerContext); registrationsRepository.saveRegistration(registration); Registration foundRegistration = registrationsRepository.getRegistration("12345"); Assert.assertNotNull(foundRegistration); Assert.assertEquals(expirationDate, foundRegistration.getExpirationDate()); }
public Registration getRegistration(String registrationId) throws RegistrationPersistenceException, EmptyResultDataAccessException { try { return jdbcTemplate.queryForObject("select expirationDate, registerContext from t_registrations where id=?", new Object[]{registrationId}, (ResultSet rs, int rowNum) -> { Registration registration = new Registration(); try { registration.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); registration.setRegisterContext(mapper.readValue(rs.getString("registerContext"), RegisterContext.class)); } catch (IOException e) { throw new SQLException(e); } return registration; }); } catch (EmptyResultDataAccessException e) { throw e; } catch (DataAccessException e) { throw new RegistrationPersistenceException(e); } }
RegistrationsRepository { public Registration getRegistration(String registrationId) throws RegistrationPersistenceException, EmptyResultDataAccessException { try { return jdbcTemplate.queryForObject("select expirationDate, registerContext from t_registrations where id=?", new Object[]{registrationId}, (ResultSet rs, int rowNum) -> { Registration registration = new Registration(); try { registration.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); registration.setRegisterContext(mapper.readValue(rs.getString("registerContext"), RegisterContext.class)); } catch (IOException e) { throw new SQLException(e); } return registration; }); } catch (EmptyResultDataAccessException e) { throw e; } catch (DataAccessException e) { throw new RegistrationPersistenceException(e); } } }
RegistrationsRepository { public Registration getRegistration(String registrationId) throws RegistrationPersistenceException, EmptyResultDataAccessException { try { return jdbcTemplate.queryForObject("select expirationDate, registerContext from t_registrations where id=?", new Object[]{registrationId}, (ResultSet rs, int rowNum) -> { Registration registration = new Registration(); try { registration.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); registration.setRegisterContext(mapper.readValue(rs.getString("registerContext"), RegisterContext.class)); } catch (IOException e) { throw new SQLException(e); } return registration; }); } catch (EmptyResultDataAccessException e) { throw e; } catch (DataAccessException e) { throw new RegistrationPersistenceException(e); } }  }
RegistrationsRepository { public Registration getRegistration(String registrationId) throws RegistrationPersistenceException, EmptyResultDataAccessException { try { return jdbcTemplate.queryForObject("select expirationDate, registerContext from t_registrations where id=?", new Object[]{registrationId}, (ResultSet rs, int rowNum) -> { Registration registration = new Registration(); try { registration.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); registration.setRegisterContext(mapper.readValue(rs.getString("registerContext"), RegisterContext.class)); } catch (IOException e) { throw new SQLException(e); } return registration; }); } catch (EmptyResultDataAccessException e) { throw e; } catch (DataAccessException e) { throw new RegistrationPersistenceException(e); } }  void saveRegistration(Registration registration); void updateRegistration(Registration registration); Map<String, Registration> getAllRegistrations(); Registration getRegistration(String registrationId); void removeRegistration(String registrationId); }
RegistrationsRepository { public Registration getRegistration(String registrationId) throws RegistrationPersistenceException, EmptyResultDataAccessException { try { return jdbcTemplate.queryForObject("select expirationDate, registerContext from t_registrations where id=?", new Object[]{registrationId}, (ResultSet rs, int rowNum) -> { Registration registration = new Registration(); try { registration.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); registration.setRegisterContext(mapper.readValue(rs.getString("registerContext"), RegisterContext.class)); } catch (IOException e) { throw new SQLException(e); } return registration; }); } catch (EmptyResultDataAccessException e) { throw e; } catch (DataAccessException e) { throw new RegistrationPersistenceException(e); } }  void saveRegistration(Registration registration); void updateRegistration(Registration registration); Map<String, Registration> getAllRegistrations(); Registration getRegistration(String registrationId); void removeRegistration(String registrationId);  }