LocalRegistrations { public String updateRegistrationContext(RegisterContext registerContext) throws RegistrationException, RegistrationPersistenceException { Duration duration = registrationDuration(registerContext); String registrationId = registerContext.getRegistrationId(); if (duration.isZero() && registrationId != null) { registrationsRepository.removeRegistration(registrationId); registrations.remove(registrationId); remoteRegistrations.removeRegistration(registrationId); return registrationId; } try { registerContext.getContextRegistrationList().forEach(c -> c.getEntityIdList().forEach(patterns::getPattern)); } catch (PatternSyntaxException e) { throw new RegistrationException("bad pattern", e); } if (registrationId == null || registrations.get(registrationId) == null) { registrationId = UUID.randomUUID().toString(); registerContext.setRegistrationId(registrationId); } Instant expirationDate = Instant.now().plus(duration); Registration registration; try { registration = registrationsRepository.getRegistration(registerContext.getRegistrationId()); registration.setExpirationDate(expirationDate); registration.setRegisterContext(registerContext); registrationsRepository.updateRegistration(registration); } catch (EmptyResultDataAccessException e) { registration = new Registration(expirationDate, registerContext); registrationsRepository.saveRegistration(registration); } registrations.put(registrationId, registration); remoteRegistrations.registerContext(registerContext, registrationId); return registrationId; }  String updateRegistrationContext(RegisterContext registerContext); Registration getRegistration(String registrationId); Iterator<URI> findProvidingApplication(EntityId searchEntityId, Set<String> searchAttributes); @Scheduled(fixedDelay = 60000) void purgeExpiredContextRegistrations();  }
@Test public void testRegistrationBadDuration() throws Exception { RegisterContext registerContext = createRegistrationContext(); registerContext.setDuration("PIPO"); try { localRegistrations.updateRegistrationContext(registerContext); fail("registration should fail on bad duration with RegistrationException"); } catch (RegistrationException ex) { } verify(remoteRegistrations, never()).registerContext(any(), any()); }
@Test public void testRegistrationBadPattern() throws Exception { RegisterContext registerContext = createRegistrationContext(); registerContext.getContextRegistrationList().get(0).getEntityIdList().get(0).setId("]|,\\(("); registerContext.getContextRegistrationList().get(0).getEntityIdList().get(0).setIsPattern(true); try { localRegistrations.updateRegistrationContext(registerContext); fail("registration should fail on bad pattern with RegistrationException"); } catch (RegistrationException ex) { } verify(remoteRegistrations, never()).registerContext(any(), any()); }