ConsentBuilderImpl implements ConsentBuilder { @Override public String buildConsent2Cdar2(long consentId) throws ConsentGenException { try { final ConsentDto consentDto = consentDtoFactory .createConsentDto(consentId); final String cdar2 = xmlTransformer.transform(consentDto, xacmlXslUrlProvider.getUrl(XslResource.CDAR2XSLNAME), Optional.empty(), Optional.empty()); return cdar2; } catch (final Exception e) { throw new ConsentGenException(e.getMessage(), e); } } ConsentBuilderImpl(String c2sAccountOrg,
			XacmlXslUrlProvider xacmlXslUrlProvider,
			ConsentDtoFactory consentDtoFactory, XmlTransformer xmlTransformer); @Override String buildConsent2Cdar2(long consentId); @Override String buildConsent2Xacml(Object obj); @Override String buildConsent2XacmlPdfConsentFrom(Object obj); @Override String buildConsent2XacmlPdfConsentTo(Object obj); final static String PARAM_EID; final static String PARAM_MRN; final static String PARAM_POLICY_ID; }
@SuppressWarnings("unchecked") @Test public void testBuildConsent2Cdar2() throws ConsentGenException { final long consentId = 1; final ConsentDto consentDtoMock = mock(ConsentDto.class); final String cdar2XslUrlStrMock = "cdar2XslUrlStrMock"; when(consentDtoFactoryMock.createConsentDto(anyLong())).thenReturn( consentDtoMock); final String cdar2Mock = "cdar2Mock"; when(xacmlXslUrlProvider.getUrl(XslResource.CDAR2XSLNAME)).thenReturn( cdar2XslUrlStrMock); when( xmlTransformerMock.transform(eq(consentDtoMock), eq(cdar2XslUrlStrMock), isA(Optional.class), isA(Optional.class))).thenReturn(cdar2Mock); final String cdar2 = sut.buildConsent2Cdar2(consentId); assertEquals(cdar2Mock, cdar2); }
@SuppressWarnings("unchecked") @Test public void testBuildConsent2Cdar2_ConsentGenException() throws ConsentGenException { thrown.expect(ConsentGenException.class); final long consentId = 1; final String cdar2XslUrlStrMock = "cdar2XslUrlStrMock"; final ConsentDto consentDtoMock = mock(ConsentDto.class); when(consentDtoFactoryMock.createConsentDto(anyLong())).thenReturn( consentDtoMock); when(xacmlXslUrlProvider.getUrl(XslResource.CDAR2XSLNAME)).thenReturn( cdar2XslUrlStrMock); when( xmlTransformerMock.transform(eq(consentDtoMock), eq(cdar2XslUrlStrMock), isA(Optional.class), isA(Optional.class))).thenThrow( new RuntimeException("Error in saxon transform")); sut.buildConsent2Cdar2(consentId); }