package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.clients; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import java.math.BigInteger; import java.util.Arrays; import java.util.List; import java.util.Optional; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.apache.cxf.binding.soap.SoapFault; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.github.skjolber.mockito.soap.SoapServiceRule; import at.asitplus.eidas.specific.core.test.config.dummy.MsConnectorDummyConfigMap; import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.ZmrSoapClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.ZmrSoapClient.ZmrRegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.controller.AdresssucheController.AdresssucheOutput; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasSAuthenticationException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.WorkflowException; import at.asitplus.eidas.specific.modules.core.eidas.EidasConstants; import at.gv.bmi.namespace.zmr_su.base._20040201.RequestType; import at.gv.bmi.namespace.zmr_su.base._20040201.ResponseType; import at.gv.bmi.namespace.zmr_su.base._20040201_.ServicePort; import at.gv.bmi.namespace.zmr_su.zmr._20040201.EidasIdentitaetAnlageType; import at.gv.bmi.namespace.zmr_su.zmr._20040201.EidasSuchdatenType; import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonAendernRequest; import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonSuchenRequest; import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonensucheInfoType; import at.gv.e_government.reference.namespace.persondata.de._20040201.NatuerlichePersonTyp; import at.gv.e_government.reference.namespace.persondata.de._20040201.PersonenNameTyp; import at.gv.egiz.eaaf.core.exceptions.EaafException; import lombok.SneakyThrows; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/SpringTest-context_tasks_test.xml", "/SpringTest-context_basic_mapConfig.xml" }) @DirtiesContext(classMode = ClassMode.AFTER_CLASS) public class ZmrClientTest { public static final String PROCESS_GENERAL = "GP_EIDAS"; public static final String PROCESS_TASK_SEARCH = "ZPR_VO_Person_suchen_Meldevorgang"; public static final String PROCESS_TASK_UPDATE = "ZPR_VO_Person_aendern"; @Autowired MsConnectorDummyConfigMap basicConfig; @Autowired ZmrSoapClient client; @Rule public SoapServiceRule soap = SoapServiceRule.newInstance(); private ServicePort zmrMock = null; private static JAXBContext jaxbContext; /** * Initialize jUnit class. */ @BeforeClass @SneakyThrows public static void classInitializer() { jaxbContext = JAXBContext.newInstance( at.gv.bmi.namespace.zmr_su.zmr._20040201.ObjectFactory.class, at.gv.bmi.namespace.zmr_su.base._20040201.ObjectFactory.class); } /** * Initialize jUnit test. */ @Before public void initializer() { if (zmrMock == null) { zmrMock = soap.mock(ServicePort.class, "http://localhost:1234/demozmr"); } basicConfig.putConfigValue(Constants.CONIG_PROPS_EIDAS_ZMRCLIENT_UPDATE_WITH_BPK_ONLY, "false"); } @Test @SneakyThrows public void searchWithMdsEmpty() { String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); final String cc = RandomStringUtils.randomAlphabetic(2).toUpperCase(); BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/empty_zmr_result.xml")); // execute operation ZmrRegisterResult resp = client.searchWithMds(processId, givenName, familyName, dateOfBirth, cc); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); assertEquals("wrong resp size", 0, resp.getPersonResult().size()); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertEquals("eidas Docs. size", 0, pSuche.getEidasSuchdaten().size()); assertNotNull("mds", pSuche.getNatuerlichePerson()); assertEquals("req. givenName", givenName, pSuche.getNatuerlichePerson().getPersonenName().getVorname()); assertEquals("req. familyName", familyName, pSuche.getNatuerlichePerson().getPersonenName().getFamilienname()); assertEquals("req. dateOfBirth", dateOfBirth, pSuche.getNatuerlichePerson().getGeburtsdatum()); } @Test @SneakyThrows public void searchWithMdsGetHistoricInfos() { String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); final String cc = "EE"; BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_historicIncluded.xml")); // execute operation ZmrRegisterResult resp = client.searchWithMds(processId, givenName, familyName, dateOfBirth, cc); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000080", resp.getProcessId().toString()); assertEquals("wrong resp size", 0, resp.getPersonResult().size()); } @Test @SneakyThrows public void searchWithMdsSuccess() { String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); final String cc = "EE"; BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_moreThanOne_2.xml")); // execute operation ZmrRegisterResult resp = client.searchWithMds(processId, givenName, familyName, dateOfBirth, cc); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000080", resp.getProcessId().toString()); assertEquals("wrong resp size", 2, resp.getPersonResult().size()); // check first person RegisterResult persInfo = resp.getPersonResult().get(0); assertEquals("bPK", "9/MtsPZgBHQMBpQOD6aOY2TUqcY=", persInfo.getBpk()); assertEquals("dateOfBirth", "1983-06-04", persInfo.getDateOfBirth()); assertEquals("familyName", "XXXTüzekçi", persInfo.getFamilyName()); assertEquals("givenName", "XXXŐzgür", persInfo.getGivenName()); assertNull("placeOfBirth", persInfo.getPlaceOfBirth()); assertNull("birthName", persInfo.getBirthName()); assertEquals("num. stored eIDAS identifiers", 1, persInfo.getPseudonym().size()); assertEquals("stored eIDAS identifiers", "aabbcc_should_not_be_included_for_DE", persInfo.getPseudonym().get(0)); // check second person RegisterResult persInfo2 = resp.getPersonResult().get(1); assertEquals("bPK", "UgeknNsc26lVuB7U/uYGVmWtnnA=", persInfo2.getBpk()); assertEquals("dateOfBirth", "1983-06-04", persInfo2.getDateOfBirth()); assertEquals("familyName", "XXXTüzekçi", persInfo2.getFamilyName()); assertEquals("givenName", "XXXŐzgür", persInfo2.getGivenName()); assertEquals("num. stored eIDAS identifiers", 1, persInfo2.getPseudonym().size()); assertEquals("stored eIDAS identifiers", "7cEYSvKZasdfsafsaf4CDVzNT4E7cjkU4Vq_first", persInfo2.getPseudonym().get(0)); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertEquals("eidas Docs. size", 0, pSuche.getEidasSuchdaten().size()); assertNotNull("mds", pSuche.getNatuerlichePerson()); assertEquals("req. givenName", givenName, pSuche.getNatuerlichePerson().getPersonenName().getVorname()); assertEquals("req. familyName", familyName, pSuche.getNatuerlichePerson().getPersonenName().getFamilienname()); assertEquals("req. dateOfBirth", dateOfBirth, pSuche.getNatuerlichePerson().getGeburtsdatum()); } @Test @SneakyThrows public void searchWithMdsWithClosedEntity() { String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); final String cc = "EE"; BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_moreThanOne_closed_entity.xml")); // execute operation ZmrRegisterResult resp = client.searchWithMds(processId, givenName, familyName, dateOfBirth, cc); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000080", resp.getProcessId().toString()); assertEquals("wrong resp size", 2, resp.getPersonResult().size()); // check first person RegisterResult persInfo = resp.getPersonResult().get(0); assertEquals("bPK", "9/MtsPZgBHQMBpQOD6aOY2TUqcY=", persInfo.getBpk()); assertEquals("dateOfBirth", "1983-06-04", persInfo.getDateOfBirth()); assertEquals("familyName", "XXXTüzekçi", persInfo.getFamilyName()); assertEquals("givenName", "XXXŐzgür", persInfo.getGivenName()); assertNull("placeOfBirth", persInfo.getPlaceOfBirth()); assertNull("birthName", persInfo.getBirthName()); assertEquals("num. stored eIDAS identifiers", 1, persInfo.getPseudonym().size()); assertEquals("stored eIDAS identifiers", "aabbcc_should_not_be_included_for_DE", persInfo.getPseudonym().get(0)); // check second person RegisterResult persInfo2 = resp.getPersonResult().get(1); assertEquals("bPK", "UgeknNsc26lVuB7U/uYGVmWtnnA=", persInfo2.getBpk()); assertEquals("dateOfBirth", "1983-06-04", persInfo2.getDateOfBirth()); assertEquals("familyName", "XXXTüzekçi", persInfo2.getFamilyName()); assertEquals("givenName", "XXXŐzgür", persInfo2.getGivenName()); assertEquals("num. stored eIDAS identifiers", 1, persInfo2.getPseudonym().size()); assertEquals("stored eIDAS identifiers", "7cEYSvKZasdfsafsaf4CDVzNT4E7cjkU4Vq_first", persInfo2.getPseudonym().get(0)); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertEquals("eidas Docs. size", 0, pSuche.getEidasSuchdaten().size()); assertNotNull("mds", pSuche.getNatuerlichePerson()); assertEquals("req. givenName", givenName, pSuche.getNatuerlichePerson().getPersonenName().getVorname()); assertEquals("req. familyName", familyName, pSuche.getNatuerlichePerson().getPersonenName().getFamilienname()); assertEquals("req. dateOfBirth", dateOfBirth, pSuche.getNatuerlichePerson().getGeburtsdatum()); } //TODO: test does not throw the valid exception to catch the error that we like to test. @Ignore @Test @SneakyThrows public void searchWithPersonalIdentifierZmrError() { final String personalIdentifierFirst = RandomStringUtils.randomAlphanumeric(10); final String cc = RandomStringUtils.randomAlphabetic(2).toUpperCase(); // inject response when(zmrMock.service(any(), any())).thenThrow(injectError(false)); // execute operation EidasSAuthenticationException error = assertThrows("wrong Exception", EidasSAuthenticationException.class, () -> client.searchWithPersonIdentifier(null, personalIdentifierFirst, cc)); assertEquals("wrong errorCode", "module.eidasauth.matching.01", error.getErrorId()); } @Test @SneakyThrows public void searchWithPersonalIdentifierZmrGenericError() { final String personalIdentifierFirst = RandomStringUtils.randomAlphanumeric(10); final String cc = RandomStringUtils.randomAlphabetic(2).toUpperCase(); // inject response when(zmrMock.service(any(), any())).thenThrow(injectError(true)); // execute operation EidasSAuthenticationException error = assertThrows("wrong Exception", EidasSAuthenticationException.class, () -> client.searchWithPersonIdentifier(null, personalIdentifierFirst, cc)); assertEquals("wrong errorCode", "module.eidasauth.matching.99", error.getErrorId()); } @Test @SneakyThrows public void searchWithPersonalIdentifierGetHistoricInfos() { final String personalIdentifierFirst = RandomStringUtils.randomAlphanumeric(10); final String cc = RandomStringUtils.randomAlphabetic(2).toUpperCase(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_historicIncluded.xml")); // execute operation EidasSAuthenticationException error = assertThrows("wrong Exception", EidasSAuthenticationException.class, () -> client.searchWithPersonIdentifier(null, personalIdentifierFirst, cc)); assertEquals("wrong errorCode", "module.eidasauth.matching.99", error.getErrorId()); assertEquals("wrong errorCode", "module.eidasauth.matching.02", ((EaafException) error.getCause()).getErrorId()); } @Test @SneakyThrows public void searchWithPersonalIdentifierEmptyResult() { final String personalIdentifierFirst = RandomStringUtils.randomAlphanumeric(10); final String cc = RandomStringUtils.randomAlphabetic(2).toUpperCase(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/empty_zmr_result.xml")); // execute operation ZmrRegisterResult resp = client.searchWithPersonIdentifier(null, personalIdentifierFirst, cc); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); assertEquals("wrong resp size", 0, resp.getPersonResult().size()); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, null, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertEquals("eidas Docs. size", 1, pSuche.getEidasSuchdaten().size()); checkEidasDocumentResult(pSuche.getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", cc, personalIdentifierFirst); assertNull("mds", pSuche.getNatuerlichePerson()); } @Test @SneakyThrows public void searchWithPersonalIdentifierMoreThanOneResult() { final String personalIdentifierFirst = RandomStringUtils.randomAlphanumeric(10); final String cc = RandomStringUtils.randomAlphabetic(2).toUpperCase(); // inject response when(zmrMock.service(any(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_moreThanOne.xml")); // execute operation WorkflowException error = assertThrows("wrong Exception", WorkflowException.class, () -> client.searchWithPersonIdentifier(null, personalIdentifierFirst, cc)); assertEquals("wrong errorCode", "module.eidasauth.matching.03", error.getErrorId()); assertEquals("wrong param 1", "Searching PersonIdentifier", error.getParams()[0]); assertEquals("wrong param 2", "Find more-than-one ZMR entry with search criteria that has to be unique", error.getParams()[1]); } @Test @SneakyThrows public void searchWithPersonalIdentifierClosedEntry() { final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_closed_entry.xml")); // execute operation EidasSAuthenticationException error = assertThrows("wrong Exception", EidasSAuthenticationException.class, () -> client.searchWithPersonIdentifier(null, personalIdentifierFirst, cc)); assertEquals("wrong errorCode", "module.eidasauth.matching.03", error.getErrorId()); } @Test @SneakyThrows public void searchWithPersonalIdentifierNotYetClosed() { final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) .pseudonym(personalIdentifierFirst) .build(); BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_closed_entry_future.xml")); // execute operation ZmrRegisterResult resp = client.searchWithPersonIdentifier(processId, eidasDataFirst.getPseudonym(), eidasDataFirst.getCitizenCountryCode()); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); } @Test @SneakyThrows public void searchWithPersonalIdentifierSuccess() { final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) .pseudonym(personalIdentifierFirst) .build(); BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp.xml")); // execute operation ZmrRegisterResult resp = client.searchWithPersonIdentifier(processId, eidasDataFirst.getPseudonym(), eidasDataFirst.getCitizenCountryCode()); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); RegisterResult persInfo = resp.getPersonResult().get(0); assertEquals("bPK", "UgeknNsc26lVuB7U/uYGVmWtnnA=", persInfo.getBpk()); assertEquals("dateOfBirth", eidasDataFirst.getDateOfBirth(), persInfo.getDateOfBirth()); assertEquals("familyName", eidasDataFirst.getFamilyName(), persInfo.getFamilyName()); assertEquals("givenName", eidasDataFirst.getGivenName(), persInfo.getGivenName()); assertEquals("placeOfBirth", "Hintergigritzpotschn", persInfo.getPlaceOfBirth()); assertEquals("birthName", "XXXvon Heuburg", persInfo.getBirthName()); assertEquals("num. stored eIDAS identifiers", 2, persInfo.getPseudonym().size()); assertEquals("stored eIDAS identifiers", "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", persInfo.getPseudonym().get(0)); assertEquals("stored eIDAS identifiers", "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit_second_one", persInfo.getPseudonym().get(1)); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertEquals("eidas Docs. size", 1, pSuche.getEidasSuchdaten().size()); checkEidasDocumentResult(pSuche.getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", cc, personalIdentifierFirst); assertNull("mds", pSuche.getNatuerlichePerson()); } @Test @SneakyThrows public void searchWithPersonalIdentifierNoBpkZP() { final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) .pseudonym(personalIdentifierFirst) .build(); BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/no_bpk_zp.xml")); // execute operation ZmrRegisterResult resp = client.searchWithPersonIdentifier(processId, eidasDataFirst.getPseudonym(), eidasDataFirst.getCitizenCountryCode()); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); RegisterResult persInfo = resp.getPersonResult().get(0); assertNull("bPK", persInfo.getBpk()); assertEquals("dateOfBirth", eidasDataFirst.getDateOfBirth(), persInfo.getDateOfBirth()); assertEquals("familyName", eidasDataFirst.getFamilyName(), persInfo.getFamilyName()); assertEquals("givenName", eidasDataFirst.getGivenName(), persInfo.getGivenName()); assertEquals("placeOfBirth", "Hintergigritzpotschn", persInfo.getPlaceOfBirth()); assertEquals("birthName", "XXXvon Heuburg", persInfo.getBirthName()); assertEquals("num. stored eIDAS identifiers", 2, persInfo.getPseudonym().size()); assertEquals("stored eIDAS identifiers", "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", persInfo.getPseudonym().get(0)); assertEquals("stored eIDAS identifiers", "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit_second_one", persInfo.getPseudonym().get(1)); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertEquals("eidas Docs. size", 1, pSuche.getEidasSuchdaten().size()); checkEidasDocumentResult(pSuche.getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", cc, personalIdentifierFirst); assertNull("mds", pSuche.getNatuerlichePerson()); } @Test @SneakyThrows public void searchCcSpecificEmpty() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final String cc = "DE"; String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); String personalIdentifier = RandomStringUtils.randomAlphabetic(10); String placeOfBirth = RandomStringUtils.randomAlphabetic(10); String birthName = RandomStringUtils.randomAlphabetic(10); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/empty_zmr_result.xml")); // execute operation ZmrRegisterResult resp = client.searchCountrySpecific(processId, generateCustomRequest(cc, familyName, givenName, dateOfBirth, personalIdentifier, placeOfBirth, birthName), cc); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); assertEquals("wrong resp size", 0, resp.getPersonResult().size()); } @Test @SneakyThrows public void searchCcSpecificMoreThanOneResult() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final String cc = "DE"; String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); String personalIdentifier = RandomStringUtils.randomAlphabetic(10); String placeOfBirth = RandomStringUtils.randomAlphabetic(10); String birthName = RandomStringUtils.randomAlphabetic(10); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_moreThanOne.xml")); // execute operation WorkflowException error = assertThrows("wrong Exception", WorkflowException.class, () -> client.searchCountrySpecific(processId, generateCustomRequest(cc, familyName, givenName, dateOfBirth, personalIdentifier, placeOfBirth, birthName), cc)); assertEquals("wrong errorCode", "module.eidasauth.matching.03", error.getErrorId()); assertEquals("wrong param 1", "Searching DE specific", error.getParams()[0]); assertEquals("wrong param 2", "Find more-than-one ZMR entry with search criteria that has to be unique", error.getParams()[1]); } @Test @SneakyThrows public void searchCcSpecificSuccess() { final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) .pseudonym(personalIdentifierFirst) .build(); BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); String personalIdentifier = RandomStringUtils.randomAlphabetic(10); String placeOfBirth = RandomStringUtils.randomAlphabetic(10); String birthName = RandomStringUtils.randomAlphabetic(10); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp.xml")); // execute operation ZmrRegisterResult resp = client.searchCountrySpecific(processId, generateCustomRequest(cc, familyName, givenName, dateOfBirth, personalIdentifier, placeOfBirth, birthName), cc); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); RegisterResult persInfo = resp.getPersonResult().get(0); assertEquals("bPK", "UgeknNsc26lVuB7U/uYGVmWtnnA=", persInfo.getBpk()); assertEquals("dateOfBirth", eidasDataFirst.getDateOfBirth(), persInfo.getDateOfBirth()); assertEquals("familyName", eidasDataFirst.getFamilyName(), persInfo.getFamilyName()); assertEquals("givenName", eidasDataFirst.getGivenName(), persInfo.getGivenName()); assertEquals("placeOfBirth", "Hintergigritzpotschn", persInfo.getPlaceOfBirth()); assertEquals("birthName", "XXXvon Heuburg", persInfo.getBirthName()); assertEquals("num. stored eIDAS identifiers", 2, persInfo.getPseudonym().size()); assertEquals("stored eIDAS identifiers", "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", persInfo.getPseudonym().get(0)); assertEquals("stored eIDAS identifiers", "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit_second_one", persInfo.getPseudonym().get(1)); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertEquals("eidas Docs. size", 3, pSuche.getEidasSuchdaten().size()); checkEidasDocumentResult(pSuche.getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PlaceOfBirth", cc, placeOfBirth); checkEidasDocumentResult(pSuche.getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/BirthName", cc, birthName); checkEidasDocumentResult(pSuche.getEidasSuchdaten(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", cc, personalIdentifier); assertNotNull("mds", pSuche.getNatuerlichePerson()); assertEquals("req. givenName", givenName, pSuche.getNatuerlichePerson().getPersonenName().getVorname()); assertEquals("req. familyName", familyName, pSuche.getNatuerlichePerson().getPersonenName().getFamilienname()); assertEquals("req. dateOfBirth", dateOfBirth, pSuche.getNatuerlichePerson().getGeburtsdatum()); } @Test @SneakyThrows public void searchResidenceEmpty() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final String cc = "DE"; String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); AdresssucheOutput addressInfo = AdresssucheOutput.builder() .municipality(RandomStringUtils.randomAlphabetic(10)) .number(RandomStringUtils.randomAlphabetic(10)) .postleitzahl(RandomStringUtils.randomAlphabetic(10)) .street(RandomStringUtils.randomAlphabetic(10)) .village(RandomStringUtils.randomAlphabetic(10)) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/empty_zmr_result.xml")); // execute operation ZmrRegisterResult resp = client.searchWithResidenceData(processId, givenName, familyName, dateOfBirth, cc, addressInfo); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); assertEquals("wrong resp size", 0, resp.getPersonResult().size()); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertNotNull("mds", pSuche.getNatuerlichePerson()); assertEquals("req. givenName", givenName, pSuche.getNatuerlichePerson().getPersonenName().getVorname()); assertEquals("req. familyName", familyName, pSuche.getNatuerlichePerson().getPersonenName().getFamilienname()); assertEquals("req. dateOfBirth", dateOfBirth, pSuche.getNatuerlichePerson().getGeburtsdatum()); assertEquals("req. Municipality", addressInfo.getMunicipality(), pSuche.getPostAdresse().getGemeinde()); assertEquals("req. Postleitzahl", addressInfo.getPostleitzahl(), pSuche.getPostAdresse().getPostleitzahl()); assertEquals("req. Village", addressInfo.getVillage(), pSuche.getPostAdresse().getOrtschaft()); assertEquals("req. Street", addressInfo.getStreet(), pSuche.getPostAdresse().getZustelladresse().getStrassenname()); assertEquals("req. Number", addressInfo.getNumber(), pSuche.getPostAdresse().getZustelladresse().getOrientierungsnummer()); } @Test @SneakyThrows public void searchResidenceMoreThanOneResult() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final String cc = "DE"; String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); AdresssucheOutput addressInfo = AdresssucheOutput.builder() .municipality(RandomStringUtils.randomAlphabetic(10)) .postleitzahl(RandomStringUtils.randomAlphabetic(10)) .street(RandomStringUtils.randomAlphabetic(10)) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_moreThanOne.xml")); // execute operation ZmrRegisterResult resp = client.searchWithResidenceData(processId, givenName, familyName, dateOfBirth, cc, addressInfo); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); assertEquals("wrong resp size", 2, resp.getPersonResult().size()); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); assertEquals("req. Municipality", addressInfo.getMunicipality(), pSuche.getPostAdresse().getGemeinde()); assertEquals("req. Postleitzahl", addressInfo.getPostleitzahl(), pSuche.getPostAdresse().getPostleitzahl()); assertNull("req. Village", pSuche.getPostAdresse().getOrtschaft()); assertEquals("req. Street", addressInfo.getStreet(), pSuche.getPostAdresse().getZustelladresse().getStrassenname()); assertNull("req. Number", pSuche.getPostAdresse().getZustelladresse().getOrientierungsnummer()); } @Test @SneakyThrows public void searchResidenceSuccess() { final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) .pseudonym(personalIdentifierFirst) .build(); BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); AdresssucheOutput addressInfo = AdresssucheOutput.builder() .municipality(RandomStringUtils.randomAlphabetic(10)) .postleitzahl(RandomStringUtils.randomAlphabetic(10)) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp.xml")); // execute operation ZmrRegisterResult resp = client.searchWithResidenceData(processId, givenName, familyName, dateOfBirth, cc, addressInfo); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); RegisterResult persInfo = resp.getPersonResult().get(0); assertEquals("bPK", "UgeknNsc26lVuB7U/uYGVmWtnnA=", persInfo.getBpk()); assertEquals("dateOfBirth", eidasDataFirst.getDateOfBirth(), persInfo.getDateOfBirth()); assertEquals("familyName", eidasDataFirst.getFamilyName(), persInfo.getFamilyName()); assertEquals("givenName", eidasDataFirst.getGivenName(), persInfo.getGivenName()); assertEquals("placeOfBirth", "Hintergigritzpotschn", persInfo.getPlaceOfBirth()); assertEquals("birthName", "XXXvon Heuburg", persInfo.getBirthName()); assertEquals("num. stored eIDAS identifiers", 2, persInfo.getPseudonym().size()); assertEquals("stored eIDAS identifiers", "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit", persInfo.getPseudonym().get(0)); assertEquals("stored eIDAS identifiers", "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit_second_one", persInfo.getPseudonym().get(1)); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); assertNotNull("Personensuche req.", zmrReq.getValue().getPersonSuchenRequest()); checkBasicRequestParameters(zmrReq.getValue(), PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = zmrReq.getValue().getPersonSuchenRequest(); assertEquals("req. Municipality", addressInfo.getMunicipality(), pSuche.getPostAdresse().getGemeinde()); assertEquals("req. Postleitzahl", addressInfo.getPostleitzahl(), pSuche.getPostAdresse().getPostleitzahl()); assertNull("req. Village", pSuche.getPostAdresse().getOrtschaft()); assertNull("req. Number", pSuche.getPostAdresse().getZustelladresse()); } @Test @SneakyThrows public void searchResidenceSuccessButClosedEntity() { final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) .pseudonym(personalIdentifierFirst) .build(); BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); String familyName = RandomStringUtils.randomAlphabetic(10); String givenName = RandomStringUtils.randomAlphabetic(10); String dateOfBirth = RandomStringUtils.randomAlphabetic(10); AdresssucheOutput addressInfo = AdresssucheOutput.builder() .municipality(RandomStringUtils.randomAlphabetic(10)) .postleitzahl(RandomStringUtils.randomAlphabetic(10)) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())).thenReturn( loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_closed_entry.xml")); // execute operation ZmrRegisterResult resp = client.searchWithResidenceData(processId, givenName, familyName, dateOfBirth, cc, addressInfo); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "367100000000079", resp.getProcessId().toString()); // we get zero results because address is found but entity was closed assertEquals("wrong resp size", 0, resp.getPersonResult().size()); } @Test @SneakyThrows public void updateProcessNoLatestVersionResult() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final String personalIdentifier = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasData = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifier) .pseudonym(personalIdentifier) .birthName("XXXvon Heuburg") .placeOfBirth("Hintergigritzpotschn") .build(); RegisterResult toUpdate = RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .dateOfBirth("1994-12-31") .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") //.birthName("") //.placeOfBirth("") //.pseudonym(Arrays.asList("")) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/empty_zmr_result.xml")) .thenThrow(new RuntimeException("Request not needed any more")); // execute operation WorkflowException error = assertThrows("wrong Exception", WorkflowException.class, () -> client.update(processId, toUpdate, eidasData)); assertEquals("wrong errorCode", "module.eidasauth.matching.03", error.getErrorId()); assertEquals("wrong param 1", "KITT get-latest-version", error.getParams()[0]); assertEquals("wrong param 2", "Find NO data-set with already matchted eID during ZMR KITT process", error.getParams()[1]); } @Test @SneakyThrows public void updateProcessMultiLatestVersionResult() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final String personalIdentifier = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasData = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifier) .pseudonym(personalIdentifier) .birthName("XXXvon Heuburg") .placeOfBirth("Hintergigritzpotschn") .build(); RegisterResult toUpdate = RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .dateOfBirth("1994-12-31") .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") //.birthName("") //.placeOfBirth("") //.pseudonym(Arrays.asList("")) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/search_with_personalId_only_resp_moreThanOne.xml")) .thenThrow(new RuntimeException("Request not needed any more")); // execute operation WorkflowException error = assertThrows("wrong Exception", WorkflowException.class, () -> client.update(processId, toUpdate, eidasData)); assertEquals("wrong errorCode", "module.eidasauth.matching.03", error.getErrorId()); assertEquals("wrong param 1", "KITT get-latest-version", error.getParams()[0]); assertEquals("wrong param 2", "Find MORE-THAN-ONE data-sets with already matchted eID during ZMR KITT process", error.getParams()[1]); } @Test @SneakyThrows public void updateProcessRequired() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final String personalIdentifier = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasData = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifier) .pseudonym(personalIdentifier) .birthName("XXXvon Heuburg") .placeOfBirth("Hintergigritzpotschn") .build(); RegisterResult toUpdate = RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .dateOfBirth("1994-12-31") .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") //.birthName("") //.placeOfBirth("") //.pseudonym(Arrays.asList("")) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-4_kitt_get_latest_version_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-6_kitt_update_resp.xml")) .thenThrow(new RuntimeException("Request not needed any more")); // execute operation ZmrRegisterResult resp = client.update(processId, toUpdate, eidasData); // validate request assertEquals("wrong number of req.", 2, zmrReq.getAllValues().size()); // check get laterst version request RequestType firstReq = zmrReq.getAllValues().get(0); assertNotNull("1 req.", firstReq.getPersonSuchenRequest()); checkBasicRequestParameters(firstReq , PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = firstReq .getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertNull("1 req. ZMR Zahl", pSuche.getZMRZahl()); assertEquals("1 req. identifier size", 1, pSuche.getNatuerlichePerson().getIdentification().size()); assertEquals("1 req. givenName", toUpdate.getBpk(), pSuche.getNatuerlichePerson().getIdentification().get(0).getValue()); assertEquals("1 req. givenName", "urn:publicid:gv.at:cdid+ZP", pSuche.getNatuerlichePerson().getIdentification().get(0).getType()); assertNotNull("1 mds", pSuche.getNatuerlichePerson()); assertEquals("1 req. givenName", toUpdate.getGivenName(), pSuche.getNatuerlichePerson().getPersonenName().getVorname()); assertEquals("1 req. familyName", toUpdate.getFamilyName(), pSuche.getNatuerlichePerson().getPersonenName().getFamilienname()); assertEquals("1 req. dateOfBirth", toUpdate.getDateOfBirth(), pSuche.getNatuerlichePerson().getGeburtsdatum()); // check update request RequestType secondReq = zmrReq.getAllValues().get(1); assertNotNull("2 req.", secondReq.getPersonAendernRequest()); checkBasicRequestParameters(secondReq , PROCESS_TASK_UPDATE, processId, "jUnit123456"); PersonAendernRequest secondpSuche = secondReq.getPersonAendernRequest(); assertEquals("2 req. ZMR Zahl", "000430320173", secondpSuche.getPersonReferenz().getZMRZahl()); assertEquals("2 req. tech. Ref. value", "44453600000000697", secondpSuche.getPersonReferenz().getTechnisch().getEntityID()); assertEquals("2 req. tech. Ref. date", "2020-02-05T13:07:06.311", secondpSuche.getPersonReferenz().getTechnisch().getLetzteAenderung().toString()); assertEquals("eidas Docs. size", 6, secondpSuche.getEidasIdentitaetAnlage().size()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/PlaceOfBirth", cc, eidasData.getPlaceOfBirth()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/BirthName", cc, eidasData.getBirthName()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", cc, eidasData.getPseudonym()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/CurrentGivenName", cc, eidasData.getGivenName()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/CurrentFamilyName", cc, eidasData.getFamilyName()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/DateOfBirth", cc, eidasData.getDateOfBirth()); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "366200000000082", resp.getProcessId().toString()); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); } @Test @SneakyThrows public void updateProcessRequiredWithBpkOnly() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); basicConfig.putConfigValue(Constants.CONIG_PROPS_EIDAS_ZMRCLIENT_UPDATE_WITH_BPK_ONLY, "true"); final String personalIdentifier = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasData = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifier) .pseudonym(personalIdentifier) .birthName("XXXvon Heuburg") .placeOfBirth("Hintergigritzpotschn") .build(); RegisterResult toUpdate = RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .dateOfBirth("1994-12-31") .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") //.birthName("") //.placeOfBirth("") //.pseudonym(Arrays.asList("")) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-4_kitt_get_latest_version_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-6_kitt_update_resp.xml")) .thenThrow(new RuntimeException("Request not needed any more")); // execute operation ZmrRegisterResult resp = client.update(processId, toUpdate, eidasData); // validate request assertEquals("wrong number of req.", 2, zmrReq.getAllValues().size()); // check get laterst version request RequestType firstReq = zmrReq.getAllValues().get(0); assertNotNull("1 req.", firstReq.getPersonSuchenRequest()); checkBasicRequestParameters(firstReq , PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = firstReq .getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertNull("1 req. ZMR Zahl", pSuche.getZMRZahl()); assertEquals("1 req. identifier size", 1, pSuche.getNatuerlichePerson().getIdentification().size()); assertEquals("1 req. givenName", toUpdate.getBpk(), pSuche.getNatuerlichePerson().getIdentification().get(0).getValue()); assertEquals("1 req. givenName", "urn:publicid:gv.at:cdid+ZP", pSuche.getNatuerlichePerson().getIdentification().get(0).getType()); assertNotNull("1 mds", pSuche.getNatuerlichePerson()); assertNull("1 req. givenName", pSuche.getNatuerlichePerson().getPersonenName().getVorname()); assertNull("1 req. familyName", pSuche.getNatuerlichePerson().getPersonenName().getFamilienname()); assertNull("1 req. dateOfBirth", pSuche.getNatuerlichePerson().getGeburtsdatum()); // check update request RequestType secondReq = zmrReq.getAllValues().get(1); assertNotNull("2 req.", secondReq.getPersonAendernRequest()); checkBasicRequestParameters(secondReq , PROCESS_TASK_UPDATE, processId, "jUnit123456"); PersonAendernRequest secondpSuche = secondReq.getPersonAendernRequest(); assertEquals("2 req. ZMR Zahl", "000430320173", secondpSuche.getPersonReferenz().getZMRZahl()); assertEquals("2 req. tech. Ref. value", "44453600000000697", secondpSuche.getPersonReferenz().getTechnisch().getEntityID()); assertEquals("2 req. tech. Ref. date", "2020-02-05T13:07:06.311", secondpSuche.getPersonReferenz().getTechnisch().getLetzteAenderung().toString()); assertEquals("eidas Docs. size", 6, secondpSuche.getEidasIdentitaetAnlage().size()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/PlaceOfBirth", cc, eidasData.getPlaceOfBirth()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/BirthName", cc, eidasData.getBirthName()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", cc, eidasData.getPseudonym()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/CurrentGivenName", cc, eidasData.getGivenName()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/CurrentFamilyName", cc, eidasData.getFamilyName()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/DateOfBirth", cc, eidasData.getDateOfBirth()); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "366200000000082", resp.getProcessId().toString()); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); } @Test @SneakyThrows public void updateProcessNoUpdateRequired() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final String personalIdentifier = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; final String cc = "DE"; final SimpleEidasData eidasData = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifier) .pseudonym(personalIdentifier) .birthName("XXXvon Heuburg") .placeOfBirth("Hintergigritzpotschn") .build(); RegisterResult toUpdate = RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .dateOfBirth("1994-12-31") .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .birthName("XXXvon Heuburg") .placeOfBirth("Hintergigritzpotschn") .pseudonym(Arrays.asList(personalIdentifier)) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-8_search_with_personalId_only_resp.xml")) .thenThrow(new RuntimeException("Request not needed any more")); // execute operation ZmrRegisterResult resp = client.update(processId, toUpdate, eidasData); // validate request assertEquals("wrong number of req.", 1, zmrReq.getAllValues().size()); // check get laterst version request RequestType firstReq = zmrReq.getAllValues().get(0); assertNotNull("1 req.", firstReq.getPersonSuchenRequest()); checkBasicRequestParameters(firstReq , PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = firstReq .getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertNull("1 req. ZMR Zahl", pSuche.getZMRZahl()); assertEquals("1 req. identifier size", 1, pSuche.getNatuerlichePerson().getIdentification().size()); assertEquals("1 req. givenName", toUpdate.getBpk(), pSuche.getNatuerlichePerson().getIdentification().get(0).getValue()); assertEquals("1 req. givenName", "urn:publicid:gv.at:cdid+ZP", pSuche.getNatuerlichePerson().getIdentification().get(0).getType()); assertNotNull("1 mds", pSuche.getNatuerlichePerson()); assertEquals("1 req. givenName", toUpdate.getGivenName(), pSuche.getNatuerlichePerson().getPersonenName().getVorname()); assertEquals("1 req. familyName", toUpdate.getFamilyName(), pSuche.getNatuerlichePerson().getPersonenName().getFamilienname()); assertEquals("1 req. dateOfBirth", toUpdate.getDateOfBirth(), pSuche.getNatuerlichePerson().getGeburtsdatum()); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", processId.toString(), resp.getProcessId().toString()); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); } @Test @SneakyThrows public void updateProcessSomeSpecialCases() { BigInteger processId = new BigInteger(RandomStringUtils.randomNumeric(6)); final String personalIdentifier = RandomStringUtils.randomAlphanumeric(10); final String cc = "DE"; final SimpleEidasData eidasData = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .dateOfBirth("1994-12-31") .personalIdentifier(cc + "/AT/" + personalIdentifier) .pseudonym(personalIdentifier) .birthName("") //empty addr. values should be ignored .placeOfBirth(RandomStringUtils.randomAlphabetic(10)) //should be ignored because it was already set for DE .build(); RegisterResult toUpdate = RegisterResult.builder() .bpk("UgeknNsc26lVuB7U/uYGVmWtnnA=") .dateOfBirth("1994-12-31") .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") .birthName("XXXvon Heuburg") .placeOfBirth("Hintergigritzpotschn") .pseudonym(Arrays.asList("7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit")) .build(); final ArgumentCaptor zmrReq = ArgumentCaptor.forClass(RequestType.class); // inject response when(zmrMock.service(zmrReq.capture(), any())) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-8_search_with_personalId_only_resp.xml")) .thenReturn(loadResponseFromFile("/data/zmr/seq_1-6_kitt_update_resp.xml")) .thenThrow(new RuntimeException("Request not needed any more")); // execute operation ZmrRegisterResult resp = client.update(processId, toUpdate, eidasData); // validate request assertEquals("wrong number of req.", 2, zmrReq.getAllValues().size()); // check get latest version request RequestType firstReq = zmrReq.getAllValues().get(0); assertNotNull("1 req.", firstReq.getPersonSuchenRequest()); checkBasicRequestParameters(firstReq , PROCESS_TASK_SEARCH, processId, "jUnit123456"); PersonSuchenRequest pSuche = firstReq .getPersonSuchenRequest(); checkSearchParameters(pSuche.getPersonensucheInfo()); assertNull("1 req. ZMR Zahl", pSuche.getZMRZahl()); assertEquals("1 req. identifier size", 1, pSuche.getNatuerlichePerson().getIdentification().size()); assertEquals("1 req. givenName", toUpdate.getBpk(), pSuche.getNatuerlichePerson().getIdentification().get(0).getValue()); assertEquals("1 req. givenName", "urn:publicid:gv.at:cdid+ZP", pSuche.getNatuerlichePerson().getIdentification().get(0).getType()); assertNotNull("1 mds", pSuche.getNatuerlichePerson()); assertEquals("1 req. givenName", toUpdate.getGivenName(), pSuche.getNatuerlichePerson().getPersonenName().getVorname()); assertEquals("1 req. familyName", toUpdate.getFamilyName(), pSuche.getNatuerlichePerson().getPersonenName().getFamilienname()); assertEquals("1 req. dateOfBirth", toUpdate.getDateOfBirth(), pSuche.getNatuerlichePerson().getGeburtsdatum()); // check update request RequestType secondReq = zmrReq.getAllValues().get(1); assertNotNull("2 req.", secondReq.getPersonAendernRequest()); checkBasicRequestParameters(secondReq , PROCESS_TASK_UPDATE, processId, "jUnit123456"); PersonAendernRequest secondpSuche = secondReq.getPersonAendernRequest(); assertEquals("2 req. ZMR Zahl", "000430320173", secondpSuche.getPersonReferenz().getZMRZahl()); assertEquals("2 req. tech. Ref. value", "44453600000000697", secondpSuche.getPersonReferenz().getTechnisch().getEntityID()); assertEquals("2 req. tech. Ref. date", "2020-02-05T13:07:06.311", secondpSuche.getPersonReferenz().getTechnisch().getLetzteAenderung().toString()); // only one attribute for update because birthname is empty and placeOfBirth was already set for DE assertEquals("eidas Docs. size", 1, secondpSuche.getEidasIdentitaetAnlage().size()); checkEidasDocumentAdd(secondpSuche.getEidasIdentitaetAnlage(), "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", cc, eidasData.getPseudonym()); // validate state assertNotNull("no ZMR response", resp); assertEquals("wrong processId", "366200000000082", resp.getProcessId().toString()); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); } private PersonSuchenRequest generateCustomRequest(String cc, String familyName, String givenName, String dateOfBirth, String personalId, String placeOfBirth, String birthName) { final PersonSuchenRequest req = new PersonSuchenRequest(); // set basic MDS information final NatuerlichePersonTyp searchNatPerson = new NatuerlichePersonTyp(); req.setNatuerlichePerson(searchNatPerson); final PersonenNameTyp searchNatPersonName = new PersonenNameTyp(); searchNatPerson.setPersonenName(searchNatPersonName); searchNatPersonName.setFamilienname(familyName); searchNatPersonName.setVorname(givenName); searchNatPerson.setGeburtsdatum(dateOfBirth); // add addtional eIDAS attributes if available addIfAvailable(req.getEidasSuchdaten(), cc, EidasConstants.eIDAS_ATTRURN_PLACEOFBIRTH, placeOfBirth); addIfAvailable(req.getEidasSuchdaten(), cc, EidasConstants.eIDAS_ATTRURN_BIRTHNAME, birthName); addIfAvailable(req.getEidasSuchdaten(), cc, EidasConstants.eIDAS_ATTRURN_PERSONALIDENTIFIER, personalId); return req; } private void addIfAvailable(List eidasSuchdaten, String cc, String attrName, String attrValue) { if (StringUtils.isNotEmpty(attrValue)) { eidasSuchdaten.add(buildEidasSuchData(cc, attrName, attrValue)); } } private EidasSuchdatenType buildEidasSuchData(String cc, String attrName, String attrValue) { final EidasSuchdatenType eidasInfos = new EidasSuchdatenType(); eidasInfos.setStaatscode2(cc); eidasInfos.setEidasArt(attrName); eidasInfos.setEidasWert(attrValue); return eidasInfos; } private void checkSearchParameters(PersonensucheInfoType toCheck) { assertTrue("searchWithHistory flag", toCheck.getSuchkriterien().isInclusivHistorie()); assertFalse("withERsB flag", toCheck.getSuchkriterien().isInclusivERnP()); assertFalse("formalisiert flag", toCheck.getSuchkriterien().isFormalisiert()); assertFalse("resultWithHistory flag", toCheck.getErgebniskriterien().isInclusivHistorie()); } private void checkEidasDocumentResult(List list, String type, String cc, String value) { Optional eidasDoc = list.stream() .filter(el -> type.equals(el.getEidasArt())) .findFirst(); assertTrue("eidas doc: " + type, eidasDoc.isPresent()); assertEquals("eIDAS docType", type, eidasDoc.get().getEidasArt()); assertEquals("eIDAS docValue", value, eidasDoc.get().getEidasWert()); assertEquals("eIDAS docCC", cc, eidasDoc.get().getStaatscode2()); } private void checkEidasDocumentAdd(List list, String type, String cc, String value) { Optional eidasDoc = list.stream() .filter(el -> type.equals(el.getEidasArt())) .findFirst(); assertTrue("eidas doc: " + type, eidasDoc.isPresent()); assertEquals("eIDAS docType", type, eidasDoc.get().getEidasArt()); assertEquals("eIDAS docValue", value, eidasDoc.get().getEidasWert()); assertEquals("eIDAS docCC", cc, eidasDoc.get().getStaatscode2()); } private void checkBasicRequestParameters(RequestType requestType, String vorgangName, BigInteger processId, String behoerdennummer) { assertNotNull("no workflow infos", requestType.getWorkflowInfoClient()); assertEquals("processName", PROCESS_GENERAL, requestType.getWorkflowInfoClient().getProzessName()); assertEquals("vorgangsName", vorgangName, requestType.getWorkflowInfoClient().getVorgangName()); if (processId != null) { assertEquals("processId", processId, requestType.getWorkflowInfoClient().getProzessInstanzID()); } else { assertNull("processId", requestType.getWorkflowInfoClient().getProzessInstanzID()); } assertNotNull("no client infos", requestType.getClientInfo()); assertEquals("behoerdennummer", behoerdennummer, requestType.getClientInfo().getOrganisation() .getBehoerdenNr()); } private ResponseType loadResponseFromFile(String filepath) throws JAXBException { final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement resp = (JAXBElement) unmarshaller.unmarshal(ZmrClientTest.class.getResourceAsStream( filepath)); return (ResponseType) resp.getValue(); } private Throwable injectError(boolean isGeneric) { javax.xml.namespace.QName qName; if (isGeneric) { qName = new javax.xml.namespace.QName("urn:SZRServices", "F455", "p344"); } else { qName = new javax.xml.namespace.QName("http://bmi.gv.at/namespace/zmr-su/base/20040201#", "ServiceFault", "zmr"); } final SoapFault fault = new SoapFault( "The travel document you sent to insert a person already exists for another person. " + "Either check the document or have the person altered accordingly", qName); fault.setRole("zmr:ServiceFault"); return fault; } }