ConsentSignedMessageHandlerPolRep extends
		AbstractConsentMessageHandler { @Override public String handleMessage(String data) throws Throwable { final String messageId = generateMessageId(); logger.debug("Consent Signed Message Received: ConsentId " + new String(data)); final Long consentId = Long.parseLong(data); final SignedConsentDto consentDto = consentGetter .getSignedConsentDto(consentId); PolicyMetadataContainerDto response = null; try { final PolicyContentContainerDto request = new PolicyContentContainerDto( new PolicyContentDto(consentDto.getXacmlCcd())); response = polRepClient.addPolicies(request, false); audit(messageId, consentDto, Optional.ofNullable(response), Optional.empty()); } catch (final HttpStatusCodeException e) { logger.error( "Failed to save in policy repository with status code: " + e.getStatusCode().toString(), e); audit(messageId, consentDto, Optional.ofNullable(response), Optional.of(e)); throw e; } catch (final Exception e) { logger.error("Failed to save in policy repository", e); throw e; } return "Saved in policy repository"; }  @Override String handleMessage(String data);  }
@Test public void testHandleMessage() throws Throwable { final String data = "1"; final long dataLong = 1L; final String xacmlCcdId = "xacmlCcdId"; final String xacmlCcd = "xacmlCcd"; final byte[] xacmlCcdBytes = xacmlCcd.getBytes(); final boolean force = false; final String patientMrn = "patientMrn"; final SignedConsentDto signedConsentDto = mock(SignedConsentDto.class); when(consentGetter.getSignedConsentDto(dataLong)).thenReturn( signedConsentDto); when(signedConsentDto.getXacmlCcdId()).thenReturn(xacmlCcdId); when(signedConsentDto.getXacmlCcd()).thenReturn(xacmlCcdBytes); when(signedConsentDto.getPatientMrn()).thenReturn(patientMrn); sut.handleMessage(data); verify(polRepClient, times(1)).addPolicies( argThat(matching((PolicyContentContainerDto r) -> new String(r .getPolicies().get(0).getPolicy()).equals(xacmlCcd))), eq(force)); verify(auditService, times(1)).audit(eq(sut), anyString(), eq(POLREP_ADD_CONSENT), eq(patientMrn), anyMapOf(PredicateKey.class, String.class)); }