@Override public Optional<EndpointRegistrationDto> findEndpointRegistrationByCredentialsId( String credentialsId) throws EndpointRegistrationServiceException { try { Validate.notBlank(credentialsId, "Invalid credentials ID provided!"); return this.endpointRegistrationDao.findByCredentialsId(credentialsId).map( EndpointRegistration::toDto); } catch (Exception cause) { LOG.error("An unexpected exception occured while searching for endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } }
@Override public Optional<EndpointRegistrationDto> findEndpointRegistrationByEndpointId(String endpointId) throws EndpointRegistrationServiceException { try { Validate.notBlank(endpointId, "Invalid endpoint ID provided!"); return this.endpointRegistrationDao.findByEndpointId(endpointId) .map(EndpointRegistration::toDto); } catch (Exception cause) { LOG.error("An unexpected exception occured while searching for endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } }
@Override public void removeEndpointRegistrationByEndpointId(String endpointId) throws EndpointRegistrationServiceException { try { Validate.notBlank(endpointId, "Invalid endpoint ID provided!"); this.endpointRegistrationDao.removeByEndpointId(endpointId); } catch (Exception cause) { LOG.error("An unexpected exception occured while removing endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } }
@Test public void testRemoveByEndpointId() throws Exception { EndpointRegistrationDto endpointRegistrationDto = this.generateEndpointRegistration(APPLICATION_ID, ENDPOINT_ID, CREDENTIALS_ID, null, null); Assert.assertNotNull(endpointRegistrationDto); Assert.assertNotNull(endpointRegistrationDto.getId()); this.endpointRegistrationDao.removeByEndpointId(ENDPOINT_ID); Assert.assertNull(this.endpointRegistrationDao.findByEndpointId(ENDPOINT_ID).orElse(null)); } }
@Override public EndpointRegistrationDto saveEndpointRegistration( EndpointRegistrationDto endpointRegistration) throws EndpointRegistrationServiceException { try { Validate.notNull(endpointRegistration, "Invalid endpoint registration provided!"); String credentialsId = endpointRegistration.getCredentialsId(); Optional<EndpointRegistrationDto> oldRegistration = findEndpointRegistrationByCredentialsId(credentialsId); if (oldRegistration.isPresent()) { EndpointRegistrationDto oldRegistrationDto = oldRegistration.get(); if (oldRegistrationDto.getEndpointId() != null && !oldRegistrationDto.getEndpointId().equals(endpointRegistration.getEndpointId())) { throw new IllegalStateException("The endpoint registration with such credentials " + "already exists!"); } } return this.endpointRegistrationDao.save(endpointRegistration).toDto(); } catch (Exception cause) { LOG.error("An unexpected exception occured while saving endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } }
@Override public void removeEndpointRegistrationById(String registrationId) throws EndpointRegistrationServiceException { try { Validate.notBlank(registrationId, "Invalid registration ID provided!"); this.endpointRegistrationDao.removeById(registrationId); } catch (Exception cause) { LOG.error("An unexpected exception occured while removing endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } } }
@Test public void testRemoveByEndpointId() throws Exception { EndpointRegistrationDto endpointRegistrationDto = this.generateEndpointRegistration(APPLICATION_ID, ENDPOINT_ID, CREDENTIALS_ID); Assert.assertNotNull(endpointRegistrationDto); Assert.assertNotNull(endpointRegistrationDto.getId()); this.endpointRegistrationDao.removeByEndpointId(ENDPOINT_ID); Assert.assertNull(this.endpointRegistrationDao.findByEndpointId(ENDPOINT_ID).orElse(null)); } }
/** * Constructs an endpoint registration with the information provided and * saves it to the database. * * @param applicationId The application ID * @param endpointId The endpoint ID * @param credentialsId The credentials ID * @return The endpoint registration saved */ protected EndpointRegistrationDto generateEndpointRegistration(String applicationId, String endpointId, String credentialsId) { EndpointRegistrationDto endpointRegistration = new EndpointRegistrationDto(applicationId, endpointId, credentialsId, null, null); return this.endpointRegistrationDao.save(endpointRegistration).toDto(); }
@Test public void testFindByCredentialsId() throws Exception { EndpointRegistrationDto endpointRegistrationDto = this.generateEndpointRegistration(APPLICATION_ID, ENDPOINT_ID, CREDENTIALS_ID, null, null); Assert.assertNotNull(endpointRegistrationDto); Assert.assertNotNull(endpointRegistrationDto.getId()); EndpointRegistration endpointRegistration = this.endpointRegistrationDao.findByCredentialsId(CREDENTIALS_ID).orElse(null); Assert.assertNotNull(endpointRegistration); Assert.assertEquals(endpointRegistrationDto, endpointRegistration.toDto()); }
@Test public void testFindByEndpointId() throws Exception { EndpointRegistrationDto endpointRegistrationDto = this.generateEndpointRegistration(APPLICATION_ID, ENDPOINT_ID, CREDENTIALS_ID); Assert.assertNotNull(endpointRegistrationDto); Assert.assertNotNull(endpointRegistrationDto.getId()); EndpointRegistration endpointRegistration = this.endpointRegistrationDao.findByEndpointId(ENDPOINT_ID).orElse(null); Assert.assertNotNull(endpointRegistration); Assert.assertEquals(endpointRegistrationDto, endpointRegistration.toDto()); }
protected EndpointRegistrationDto generateEndpointRegistration( String applicationId, String endpointId, String credentialsId, Integer serverProfileVersion, String serverProfileBody) { EndpointRegistrationDto endpointRegistration = new EndpointRegistrationDto(); endpointRegistration.setApplicationId(applicationId); endpointRegistration.setEndpointId(endpointId); endpointRegistration.setCredentialsId(credentialsId); endpointRegistration.setServerProfileVersion(serverProfileVersion); endpointRegistration.setServerProfileBody(serverProfileBody); return this.endpointRegistrationDao.save(endpointRegistration).toDto(); }
@Test public void testFindByCredentialsId() throws Exception { EndpointRegistrationDto endpointRegistrationDto = this.generateEndpointRegistration(APPLICATION_ID, ENDPOINT_ID, CREDENTIALS_ID); Assert.assertNotNull(endpointRegistrationDto); Assert.assertNotNull(endpointRegistrationDto.getId()); EndpointRegistration endpointRegistration = this.endpointRegistrationDao.findByCredentialsId(CREDENTIALS_ID).orElse(null); Assert.assertNotNull(endpointRegistration); Assert.assertEquals(endpointRegistrationDto, endpointRegistration.toDto()); }
@Test public void testFindByEndpointId() throws Exception { EndpointRegistrationDto endpointRegistrationDto = this.generateEndpointRegistration(APPLICATION_ID, ENDPOINT_ID, CREDENTIALS_ID, null, null); Assert.assertNotNull(endpointRegistrationDto); Assert.assertNotNull(endpointRegistrationDto.getId()); EndpointRegistration endpointRegistration = this.endpointRegistrationDao.findByEndpointId(ENDPOINT_ID).orElse(null); Assert.assertNotNull(endpointRegistration); Assert.assertEquals(endpointRegistrationDto, endpointRegistration.toDto()); }