From f71531346c6be197957311712ba093e024545e37 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Fri, 7 Aug 2015 13:24:09 +0200 Subject: preparing the old code for the merge --- .../peps/tests/ComplexAttributesMarshalling.java | 407 ++++++++++----------- 1 file changed, 194 insertions(+), 213 deletions(-) (limited to 'id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java') diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java index fc6e65f70..b8220ce98 100644 --- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java +++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java @@ -33,262 +33,243 @@ import eu.stork.peps.complex.attributes.eu.stork.names.tc.stork._1_0.assertion.O import eu.stork.peps.complex.attributes.eu.stork.names.tc.stork._1_0.assertion.RepresentationPersonType; /** - * @author Advania Examples on how to use the jaxb marshaller. The classes are created from the - * StorkcomplexAttributes.xsd schema located in resources. - * @version $Revision: 1.00 $, $Date: 2014-17-02 11:15:00 $ + * @author Advania Examples on how to use the jaxb marshaller. The classes are created from the StorkcomplexAttributes.xsd schema located in resources. + * @version $Revision: 1.00 $, $Date: 2014-17-02 11:15:00 $ * */ public class ComplexAttributesMarshalling { - MandateContentType mtObject = new MandateContentType(); - RepresentationPersonType rpObject = new RepresentationPersonType(); - RepresentationPersonType rptObject = new RepresentationPersonType(); - - void initMandateValues() { - // Fill in the information ... - mtObject.setIsChained(false); - // mtObject.setIsJoined("IsJoined"); - mtObject.setTypeOfPower("The Force"); - mtObject.setIsChained(false); - // ... fill in info for the representative - rpObject.setTextRegisteredAddress("Address at some street"); - rpObject.setDateOfBirth(DateTime.now().toString()); - rpObject.setEIdentifier("123456"); - rpObject.setGivenName("Name of some person"); - rpObject.setLegalForm("Type of person"); - // .... fill in the info for the represented - rptObject.setTextRegisteredAddress("Another Address at some street"); - rptObject.setDateOfBirth(DateTime.now().toString()); - rptObject.setEIdentifier("654321"); - rptObject.setGivenName("Another Name of some person"); - rptObject.setLegalForm("Yet another type of person"); - } + MandateContentType mtObject = new MandateContentType(); + RepresentationPersonType rpObject = new RepresentationPersonType(); + RepresentationPersonType rptObject = new RepresentationPersonType(); + + void initMandateValues() { + // Fill in the information ... + mtObject.setIsChained(false); + // mtObject.setIsJoined("IsJoined"); + mtObject.setTypeOfPower("The Force"); + mtObject.setIsChained(false); + // ... fill in info for the representative + rpObject.setTextRegisteredAddress("Address at some street"); + rpObject.setDateOfBirth(DateTime.now().toString()); + rpObject.setEIdentifier("123456"); + rpObject.setGivenName("Name of some person"); + rpObject.setLegalForm("Type of person"); + // .... fill in the info for the represented + rptObject.setTextRegisteredAddress("Another Address at some street"); + rptObject.setDateOfBirth(DateTime.now().toString()); + rptObject.setEIdentifier("654321"); + rptObject.setGivenName("Another Name of some person"); + rptObject.setLegalForm("Yet another type of person"); + } /** - * Test marshalling canonical address - * - * IS Reykjavik RVK - * Reykjavik 101 Laugavegur - * 1 10 + * Test marshalling canonical address + * IS Reykjavik RVK Reykjavik 101 + * Laugavegur 1 10 */ @Test - public void testMarshallCanonicalResidencAddress() - { - try - { - final CanonicalAddressType object = new CanonicalAddressType(); - object.setApartmentNumber("10"); - object.setCountryCodeAddress("IS"); - object.setMunicipalityCode("RVK"); - object.setPostalCode("101"); - object.setState("Reykjavik"); - object.setStreetName("Laugavegur"); - object.setStreetNumber("1"); - object.setTown("Reykjavik"); - - final JAXBContext context = JAXBContext.newInstance(CanonicalAddressType.class); - final Marshaller m = context.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - final ObjectFactory objf = new ObjectFactory(); - - m.marshal(objf.createCanonicalResidenceAddress(object), new FileOutputStream("CanonicalAddressType.xml")); + public void testMarshallCanonicalResidencAddress() { + try { + final CanonicalAddressType object = new CanonicalAddressType(); + object.setApartmentNumber("10"); + object.setCountryCodeAddress("IS"); + object.setMunicipalityCode("RVK"); + object.setPostalCode("101"); + object.setState("Reykjavik"); + object.setStreetName("Laugavegur"); + object.setStreetNumber("1"); + object.setTown("Reykjavik"); + + final JAXBContext context = JAXBContext.newInstance(CanonicalAddressType.class); + final Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + final ObjectFactory objf = new ObjectFactory(); + + m.marshal(objf.createCanonicalResidenceAddress(object), new FileOutputStream("CanonicalAddressType.xml")); m.marshal(objf.createCanonicalResidenceAddress(object), System.out); + } catch (Exception e) { + e.printStackTrace(); } - catch ( Exception e ) { + } + + @Test + public void testForDiana() { + initMandateValues(); + + try { + // Create the marshallers' + + final JAXBContext mandateTypeContext = JAXBContext.newInstance(MandateType.class); + final Marshaller mandateMarshaller = mandateTypeContext.createMarshaller(); + final Unmarshaller mandateUnmarshaller = mandateTypeContext.createUnmarshaller(); + + // final JAXBContext MandateContentTypecontext = JAXBContext.newInstance(MandateContentType.class); + // final Marshaller mandM = MandateContentTypecontext.createMarshaller(); + // + // final JAXBContext RepresentationPersonTypecontext = + // JAXBContext.newInstance(RepresentationPersonType.class); + // final Marshaller repM = RepresentationPersonTypecontext.createMarshaller(); + // + + final ObjectFactory objf = new ObjectFactory(); + MandateType mandate = new MandateType(); + RepresentationPersonType representative = new RepresentationPersonType(); + representative.setDateOfBirth("1990-01-01"); + representative.setGivenName("Bilbo"); + representative.setSurname("Baggins"); + representative.setEIdentifier("IT/IT/12345678990"); + mandate.setRepresentative(representative); + + RepresentationPersonType represented = new RepresentationPersonType(); + represented.setTextRegisteredAddress("Via...."); + represented.setELPIdentifier("IT/1111111"); + represented.setLegalName("Shire Corp."); + mandate.setRepresented(represented); + + MandateContentType mandateContent1 = new MandateContentType(); + // OriginalMandateType omt1 = new OriginalMandateType(); + // omt1.setMimeType("text/plain"); + // omt1.setValue("Chief executive officer".getBytes()); + mandateContent1.setOriginalMandate("Chief executive officer".getBytes()); + mandateContent1.setOriginalMandateType("text/plain"); + MandateContentType mandateContent2 = new MandateContentType(); + // mandateContent2.setOriginalMandate(omt1); + mandateContent2.setOriginalMandate("Chief executive officer2".getBytes()); + mandateContent2.setOriginalMandateType("text/plain"); + mandate.getMandateContent().add(mandateContent1); + mandate.getMandateContent().add(mandateContent2); + + // create a hashmap + // HashMap complexMandate = new HashMap(); + + // marshall the mandatecontent + StringWriter sw = new StringWriter(); + mandateMarshaller.marshal(objf.createMandate(mandate), sw); + + System.out.print(sw.toString()); + + // add it to the hashmap + // complexMandate.put("representative", sw.toString()); + // sw.flush(); + // + // // continue with the rest of the objects. + // repM.marshal(objf.createRepresentationPerson(rpObject), sw); + // System.out.print(sw.toString()); + // complexMandate.put("representative", sw.toString()); + // sw.flush(); + // + // MandateType mandateType = new MandateType(); + // + // repM.marshal(objf.createRepresentationPerson(rptObject), sw); + // System.out.print(sw.toString()); + // complexMandate.put("represented", sw.toString()); + // sw.flush(); + // + // // add the complex values to the attr.list. + // PersonalAttribute pal = new PersonalAttribute(); + // + // pal.setName("mandateContent"); + // pal.setIsRequired(pal.isRequired()); + // pal.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + // pal.setComplexValue(complexMandate); + // + // System.out.println(pal.toString()); + } catch (JAXBException e) { e.printStackTrace(); - } - } - - @Test - public void testForDiana() { - initMandateValues(); - - try { - // Create the marshallers' - - final JAXBContext mandateTypeContext = JAXBContext.newInstance(MandateType.class); - final Marshaller mandateMarshaller = mandateTypeContext.createMarshaller(); - final Unmarshaller mandateUnmarshaller = mandateTypeContext.createUnmarshaller(); - - // final JAXBContext MandateContentTypecontext = JAXBContext.newInstance(MandateContentType.class); - // final Marshaller mandM = MandateContentTypecontext.createMarshaller(); - // - // final JAXBContext RepresentationPersonTypecontext = - // JAXBContext.newInstance(RepresentationPersonType.class); - // final Marshaller repM = RepresentationPersonTypecontext.createMarshaller(); - // - - final ObjectFactory objf = new ObjectFactory(); - MandateType mandate = new MandateType(); - RepresentationPersonType representative = new RepresentationPersonType(); - representative.setDateOfBirth("1990-01-01"); - representative.setGivenName("Bilbo"); - representative.setSurname("Baggins"); - representative.setEIdentifier("IT/IT/12345678990"); - mandate.setRepresentative(representative); - - RepresentationPersonType represented = new RepresentationPersonType(); - represented.setTextRegisteredAddress("Via...."); - represented.setELPIdentifier("IT/1111111"); - represented.setLegalName("Shire Corp."); - mandate.setRepresented(represented); - - MandateContentType mandateContent1 = new MandateContentType(); - // OriginalMandateType omt1 = new OriginalMandateType(); - // omt1.setMimeType("text/plain"); - // omt1.setValue("Chief executive officer".getBytes()); - mandateContent1.setOriginalMandate("Chief executive officer".getBytes()); - mandateContent1.setOriginalMandateType("text/plain"); - MandateContentType mandateContent2 = new MandateContentType(); - // mandateContent2.setOriginalMandate(omt1); - mandateContent2.setOriginalMandate("Chief executive officer2".getBytes()); - mandateContent2.setOriginalMandateType("text/plain"); - mandate.getMandateContent().add(mandateContent1); - mandate.getMandateContent().add(mandateContent2); - - // create a hashmap - // HashMap complexMandate = new HashMap(); - - // marshall the mandatecontent - StringWriter sw = new StringWriter(); - mandateMarshaller.marshal(objf.createMandate(mandate), sw); - - System.out.print(sw.toString()); - - // add it to the hashmap - // complexMandate.put("representative", sw.toString()); - // sw.flush(); - // - // // continue with the rest of the objects. - // repM.marshal(objf.createRepresentationPerson(rpObject), sw); - // System.out.print(sw.toString()); - // complexMandate.put("representative", sw.toString()); - // sw.flush(); - // - // MandateType mandateType = new MandateType(); - // - // repM.marshal(objf.createRepresentationPerson(rptObject), sw); - // System.out.print(sw.toString()); - // complexMandate.put("represented", sw.toString()); - // sw.flush(); - // - // // add the complex values to the attr.list. - // PersonalAttribute pal = new PersonalAttribute(); - // - // pal.setName("mandateContent"); - // pal.setIsRequired(pal.isRequired()); - // pal.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - // pal.setComplexValue(complexMandate); - // - // System.out.println(pal.toString()); } - catch ( JAXBException e ) { - e.printStackTrace(); - } - } - - @Test - public void testMandateContent() { - initMandateValues(); - try { - final MandateType object = new MandateType(); - // Make the object .... - object.getMandateContent().add(mtObject); - object.setRepresented(rpObject); - object.setRepresentative(rptObject); - - final JAXBContext context = JAXBContext.newInstance(MandateType.class); - // Create the marshaller - final Marshaller m = context.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - final ObjectFactory objf = new ObjectFactory(); - // Various types of output - m.marshal(objf.createMandate(object), new FileOutputStream("MandateContentType.xml")); - m.marshal(objf.createMandate(object), System.out); - - StringWriter sw = new StringWriter(); - m.marshal(objf.createMandate(object), sw); + } + + @Test + public void testMandateContent() { + initMandateValues(); + try { + final MandateType object = new MandateType(); + // Make the object .... + object.getMandateContent().add(mtObject); + object.setRepresented(rpObject); + object.setRepresentative(rptObject); + + final JAXBContext context = JAXBContext.newInstance(MandateType.class); + // Create the marshaller + final Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + final ObjectFactory objf = new ObjectFactory(); + // Various types of output + m.marshal(objf.createMandate(object), new FileOutputStream("MandateContentType.xml")); + m.marshal(objf.createMandate(object), System.out); + StringWriter sw = new StringWriter(); + m.marshal(objf.createMandate(object), sw); + + } catch (Exception e) { + e.printStackTrace(); + } } - catch ( Exception e ) { - e.printStackTrace(); - } - } /** - * Test unmarshalling canonical address - * - * IS Reykjavik RVK - * Reykjavik 101 Laugavegur - * 1 10 + * Test unmarshalling canonical address + * IS Reykjavik RVK Reykjavik 101 + * Laugavegur 1 10 */ @Test - public void testUnmarshallCanonicalAddress() - { - JAXBContext uContext; - try - { + public void testUnmarshallCanonicalAddress() { + JAXBContext uContext; + try { uContext = JAXBContext.newInstance(CanonicalAddressType.class); - final Unmarshaller u = uContext.createUnmarshaller(); - final File file = new File("CanonicalAddressType.xml"); - + final Unmarshaller u = uContext.createUnmarshaller(); + final File file = new File("CanonicalAddressType.xml"); + final JAXBElement root = u.unmarshal(new StreamSource(file), CanonicalAddressType.class); final CanonicalAddressType foo = root.getValue(); - - final String A = foo.getStreetName(); - final String B = foo.getStreetNumber(); - - System.out.println("Streetname: " + A); - System.out.println("Streetnumber: " + B); - - } - catch (final JAXBException e) - { + + final String A = foo.getStreetName(); + final String B = foo.getStreetNumber(); + + System.out.println("Streetname: " + A); + System.out.println("Streetnumber: " + B); + + } catch (final JAXBException e) { e.printStackTrace(); } } /** - * Test marshalling has bank account Arion 3 + * Test marshalling has bank account Arion + * 3 */ @Test - public void testMarshallHasBankAccount() - { - try - { + public void testMarshallHasBankAccount() { + try { final HasAccountInBankType object = new HasAccountInBankType(); object.setAQAA(3); object.setBankName("Arion Bank"); - final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class); + final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class); final Marshaller m = context.createMarshaller(); - final ObjectFactory o = new ObjectFactory(); - m.marshal(o.createHasAccountInBank(object), new FileOutputStream ("hasbankaccount.xml")); + final ObjectFactory o = new ObjectFactory(); + m.marshal(o.createHasAccountInBank(object), new FileOutputStream("hasbankaccount.xml")); m.marshal(o.createHasAccountInBank(object), System.out); - - } - catch (FileNotFoundException e) { - e.printStackTrace(); - }catch ( Exception e ) { + } catch (FileNotFoundException e) { e.printStackTrace(); - + + } catch (Exception e) { + e.printStackTrace(); + } } /** - * Test unmarshalling has bank account Arion 3 + * Test unmarshalling has bank account Arion + * 3 */ @Test - public void testUnmarshallHasBankAccount() - { - try - { + public void testUnmarshallHasBankAccount() { + try { final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class); final Unmarshaller um = context.createUnmarshaller(); - final File file = new File("hasbankaccount.xml"); + final File file = new File("hasbankaccount.xml"); final JAXBElement root = um.unmarshal(new StreamSource(file), HasAccountInBankType.class); final HasAccountInBankType foo = root.getValue(); System.out.println(foo.getBankName()); @@ -296,5 +277,5 @@ public class ComplexAttributesMarshalling { e.printStackTrace(); } } - + } -- cgit v1.2.3 From 2b8c631a8ef6d6970a482914e41c59f37e3a6d08 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Mon, 10 Aug 2015 16:52:00 +0200 Subject: approved tests --- .../peps/tests/ComplexAttributesMarshalling.java | 445 ++++++++++----------- 1 file changed, 205 insertions(+), 240 deletions(-) (limited to 'id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java') diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java index b8220ce98..f2383c07a 100644 --- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java +++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java @@ -11,7 +11,6 @@ package eu.stork.peps.tests; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.StringWriter; @@ -33,249 +32,215 @@ import eu.stork.peps.complex.attributes.eu.stork.names.tc.stork._1_0.assertion.O import eu.stork.peps.complex.attributes.eu.stork.names.tc.stork._1_0.assertion.RepresentationPersonType; /** - * @author Advania Examples on how to use the jaxb marshaller. The classes are created from the StorkcomplexAttributes.xsd schema located in resources. + * @author Advania Examples on how to use the jaxb marshaller. The classes are created from the + * StorkcomplexAttributes.xsd schema located in resources. * @version $Revision: 1.00 $, $Date: 2014-17-02 11:15:00 $ - * */ public class ComplexAttributesMarshalling { - MandateContentType mtObject = new MandateContentType(); - RepresentationPersonType rpObject = new RepresentationPersonType(); - RepresentationPersonType rptObject = new RepresentationPersonType(); - - void initMandateValues() { - // Fill in the information ... - mtObject.setIsChained(false); - // mtObject.setIsJoined("IsJoined"); - mtObject.setTypeOfPower("The Force"); - mtObject.setIsChained(false); - // ... fill in info for the representative - rpObject.setTextRegisteredAddress("Address at some street"); - rpObject.setDateOfBirth(DateTime.now().toString()); - rpObject.setEIdentifier("123456"); - rpObject.setGivenName("Name of some person"); - rpObject.setLegalForm("Type of person"); - // .... fill in the info for the represented - rptObject.setTextRegisteredAddress("Another Address at some street"); - rptObject.setDateOfBirth(DateTime.now().toString()); - rptObject.setEIdentifier("654321"); - rptObject.setGivenName("Another Name of some person"); - rptObject.setLegalForm("Yet another type of person"); - } - - /** - * Test marshalling canonical address - * IS Reykjavik RVK Reykjavik 101 - * Laugavegur 1 10 - */ - @Test - public void testMarshallCanonicalResidencAddress() { - try { - final CanonicalAddressType object = new CanonicalAddressType(); - object.setApartmentNumber("10"); - object.setCountryCodeAddress("IS"); - object.setMunicipalityCode("RVK"); - object.setPostalCode("101"); - object.setState("Reykjavik"); - object.setStreetName("Laugavegur"); - object.setStreetNumber("1"); - object.setTown("Reykjavik"); - - final JAXBContext context = JAXBContext.newInstance(CanonicalAddressType.class); - final Marshaller m = context.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - final ObjectFactory objf = new ObjectFactory(); - - m.marshal(objf.createCanonicalResidenceAddress(object), new FileOutputStream("CanonicalAddressType.xml")); - m.marshal(objf.createCanonicalResidenceAddress(object), System.out); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testForDiana() { - initMandateValues(); - - try { - // Create the marshallers' - - final JAXBContext mandateTypeContext = JAXBContext.newInstance(MandateType.class); - final Marshaller mandateMarshaller = mandateTypeContext.createMarshaller(); - final Unmarshaller mandateUnmarshaller = mandateTypeContext.createUnmarshaller(); - - // final JAXBContext MandateContentTypecontext = JAXBContext.newInstance(MandateContentType.class); - // final Marshaller mandM = MandateContentTypecontext.createMarshaller(); - // - // final JAXBContext RepresentationPersonTypecontext = - // JAXBContext.newInstance(RepresentationPersonType.class); - // final Marshaller repM = RepresentationPersonTypecontext.createMarshaller(); - // - - final ObjectFactory objf = new ObjectFactory(); - MandateType mandate = new MandateType(); - RepresentationPersonType representative = new RepresentationPersonType(); - representative.setDateOfBirth("1990-01-01"); - representative.setGivenName("Bilbo"); - representative.setSurname("Baggins"); - representative.setEIdentifier("IT/IT/12345678990"); - mandate.setRepresentative(representative); - - RepresentationPersonType represented = new RepresentationPersonType(); - represented.setTextRegisteredAddress("Via...."); - represented.setELPIdentifier("IT/1111111"); - represented.setLegalName("Shire Corp."); - mandate.setRepresented(represented); - - MandateContentType mandateContent1 = new MandateContentType(); - // OriginalMandateType omt1 = new OriginalMandateType(); - // omt1.setMimeType("text/plain"); - // omt1.setValue("Chief executive officer".getBytes()); - mandateContent1.setOriginalMandate("Chief executive officer".getBytes()); - mandateContent1.setOriginalMandateType("text/plain"); - MandateContentType mandateContent2 = new MandateContentType(); - // mandateContent2.setOriginalMandate(omt1); - mandateContent2.setOriginalMandate("Chief executive officer2".getBytes()); - mandateContent2.setOriginalMandateType("text/plain"); - mandate.getMandateContent().add(mandateContent1); - mandate.getMandateContent().add(mandateContent2); - - // create a hashmap - // HashMap complexMandate = new HashMap(); - - // marshall the mandatecontent - StringWriter sw = new StringWriter(); - mandateMarshaller.marshal(objf.createMandate(mandate), sw); - - System.out.print(sw.toString()); - - // add it to the hashmap - // complexMandate.put("representative", sw.toString()); - // sw.flush(); - // - // // continue with the rest of the objects. - // repM.marshal(objf.createRepresentationPerson(rpObject), sw); - // System.out.print(sw.toString()); - // complexMandate.put("representative", sw.toString()); - // sw.flush(); - // - // MandateType mandateType = new MandateType(); - // - // repM.marshal(objf.createRepresentationPerson(rptObject), sw); - // System.out.print(sw.toString()); - // complexMandate.put("represented", sw.toString()); - // sw.flush(); - // - // // add the complex values to the attr.list. - // PersonalAttribute pal = new PersonalAttribute(); - // - // pal.setName("mandateContent"); - // pal.setIsRequired(pal.isRequired()); - // pal.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - // pal.setComplexValue(complexMandate); - // - // System.out.println(pal.toString()); - } catch (JAXBException e) { - e.printStackTrace(); - } - } - - @Test - public void testMandateContent() { - initMandateValues(); - try { - final MandateType object = new MandateType(); - // Make the object .... - object.getMandateContent().add(mtObject); - object.setRepresented(rpObject); - object.setRepresentative(rptObject); - - final JAXBContext context = JAXBContext.newInstance(MandateType.class); - // Create the marshaller - final Marshaller m = context.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - final ObjectFactory objf = new ObjectFactory(); - // Various types of output - m.marshal(objf.createMandate(object), new FileOutputStream("MandateContentType.xml")); - m.marshal(objf.createMandate(object), System.out); - - StringWriter sw = new StringWriter(); - m.marshal(objf.createMandate(object), sw); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * Test unmarshalling canonical address - * IS Reykjavik RVK Reykjavik 101 - * Laugavegur 1 10 - */ - @Test - public void testUnmarshallCanonicalAddress() { - JAXBContext uContext; - try { - uContext = JAXBContext.newInstance(CanonicalAddressType.class); - final Unmarshaller u = uContext.createUnmarshaller(); - final File file = new File("CanonicalAddressType.xml"); - - final JAXBElement root = u.unmarshal(new StreamSource(file), CanonicalAddressType.class); - final CanonicalAddressType foo = root.getValue(); - - final String A = foo.getStreetName(); - final String B = foo.getStreetNumber(); - - System.out.println("Streetname: " + A); - System.out.println("Streetnumber: " + B); - - } catch (final JAXBException e) { - e.printStackTrace(); - } - } - - /** - * Test marshalling has bank account Arion - * 3 - */ - @Test - public void testMarshallHasBankAccount() { - try { - final HasAccountInBankType object = new HasAccountInBankType(); - object.setAQAA(3); - object.setBankName("Arion Bank"); - final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class); - final Marshaller m = context.createMarshaller(); - final ObjectFactory o = new ObjectFactory(); - m.marshal(o.createHasAccountInBank(object), new FileOutputStream("hasbankaccount.xml")); - m.marshal(o.createHasAccountInBank(object), System.out); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - - } catch (Exception e) { - e.printStackTrace(); - - } - } - - /** - * Test unmarshalling has bank account Arion - * 3 - */ - @Test - public void testUnmarshallHasBankAccount() { - try { - final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class); - final Unmarshaller um = context.createUnmarshaller(); - final File file = new File("hasbankaccount.xml"); - final JAXBElement root = um.unmarshal(new StreamSource(file), HasAccountInBankType.class); - final HasAccountInBankType foo = root.getValue(); - System.out.println(foo.getBankName()); - } catch (final JAXBException e) { - e.printStackTrace(); - } - } + MandateContentType mtObject = new MandateContentType(); + RepresentationPersonType rpObject = new RepresentationPersonType(); + RepresentationPersonType rptObject = new RepresentationPersonType(); + + void initMandateValues() { + // Fill in the information ... + mtObject.setIsChained(false); + // mtObject.setIsJoined("IsJoined"); + mtObject.setTypeOfPower("The Force"); + mtObject.setIsChained(false); + // ... fill in info for the representative + rpObject.setTextRegisteredAddress("Address at some street"); + rpObject.setDateOfBirth(DateTime.now().toString()); + rpObject.setEIdentifier("123456"); + rpObject.setGivenName("Name of some person"); + rpObject.setLegalForm("Type of person"); + // .... fill in the info for the represented + rptObject.setTextRegisteredAddress("Another Address at some street"); + rptObject.setDateOfBirth(DateTime.now().toString()); + rptObject.setEIdentifier("654321"); + rptObject.setGivenName("Another Name of some person"); + rptObject.setLegalForm("Yet another type of person"); + } + + /** + * Test marshalling canonical address + * + * IS Reykjavik RVK + * Reykjavik 101 Laugavegur + * 1 10 + */ + @Test + public void testMarshallCanonicalResidencAddress() { + try { + final CanonicalAddressType object = new CanonicalAddressType(); + object.setApartmentNumber("10"); + object.setCountryCodeAddress("IS"); + object.setMunicipalityCode("RVK"); + object.setPostalCode("101"); + object.setState("Reykjavik"); + object.setStreetName("Laugavegur"); + object.setStreetNumber("1"); + object.setTown("Reykjavik"); + + final JAXBContext context = JAXBContext.newInstance(CanonicalAddressType.class); + final Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + final ObjectFactory objf = new ObjectFactory(); + + m.marshal(objf.createCanonicalResidenceAddress(object), new FileOutputStream("CanonicalAddressType.xml")); + m.marshal(objf.createCanonicalResidenceAddress(object), System.out); + } + catch ( Exception e ) { + e.printStackTrace(); + } + } + + @Test + public void testForDiana() { + initMandateValues(); + + try { + // Create the marshallers' + + final JAXBContext mandateTypeContext = JAXBContext.newInstance(MandateType.class); + final Marshaller mandateMarshaller = mandateTypeContext.createMarshaller(); + + final ObjectFactory objf = new ObjectFactory(); + MandateType mandate = new MandateType(); + RepresentationPersonType representative = new RepresentationPersonType(); + representative.setDateOfBirth("1990-01-01"); + representative.setGivenName("Bilbo"); + representative.setSurname("Baggins"); + representative.setEIdentifier("IT/IT/12345678990"); + mandate.setRepresentative(representative); + + RepresentationPersonType represented = new RepresentationPersonType(); + represented.setTextRegisteredAddress("Via...."); + represented.setELPIdentifier("IT/1111111"); + represented.setLegalName("Shire Corp."); + mandate.setRepresented(represented); + + MandateContentType mandateContent1 = new MandateContentType(); + mandateContent1.setOriginalMandate("Chief executive officer".getBytes()); + mandateContent1.setOriginalMandateType("text/plain"); + MandateContentType mandateContent2 = new MandateContentType(); + mandateContent2.setOriginalMandate("Chief executive officer2".getBytes()); + mandateContent2.setOriginalMandateType("text/plain"); + mandate.getMandateContent().add(mandateContent1); + mandate.getMandateContent().add(mandateContent2); + + // marshall the mandatecontent + StringWriter sw = new StringWriter(); + mandateMarshaller.marshal(objf.createMandate(mandate), sw); + + System.out.print(sw.toString()); + + } + catch ( JAXBException e ) { + e.printStackTrace(); + } + } + + @Test + public void testMandateContent() { + initMandateValues(); + try { + final MandateType object = new MandateType(); + // Make the object .... + object.getMandateContent().add(mtObject); + object.setRepresented(rpObject); + object.setRepresentative(rptObject); + + final JAXBContext context = JAXBContext.newInstance(MandateType.class); + // Create the marshaller + final Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + final ObjectFactory objf = new ObjectFactory(); + // Various types of output + m.marshal(objf.createMandate(object), new FileOutputStream("MandateContentType.xml")); + m.marshal(objf.createMandate(object), System.out); + + StringWriter sw = new StringWriter(); + m.marshal(objf.createMandate(object), sw); + + } + catch ( Exception e ) { + e.printStackTrace(); + } + } + + /** + * Test unmarshalling canonical address + * + * IS Reykjavik RVK + * Reykjavik 101 Laugavegur + * 1 10 + */ + @Test + public void testUnmarshallCanonicalAddress() { + JAXBContext uContext; + try { + uContext = JAXBContext.newInstance(CanonicalAddressType.class); + final Unmarshaller u = uContext.createUnmarshaller(); + final File file = new File("CanonicalAddressType.xml"); + + final JAXBElement root = u.unmarshal(new StreamSource(file), + CanonicalAddressType.class); + final CanonicalAddressType foo = root.getValue(); + + final String A = foo.getStreetName(); + final String B = foo.getStreetNumber(); + + System.out.println("Streetname: " + A); + System.out.println("Streetnumber: " + B); + + } + catch ( final JAXBException e ) { + e.printStackTrace(); + } + } + + /** + * Test marshalling has bank account Arion 3 + */ + @Test + public void testMarshallHasBankAccount() { + try { + final HasAccountInBankType object = new HasAccountInBankType(); + object.setAQAA(3); + object.setBankName("Arion Bank"); + final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class); + final Marshaller m = context.createMarshaller(); + final ObjectFactory o = new ObjectFactory(); + m.marshal(o.createHasAccountInBank(object), new FileOutputStream("hasbankaccount.xml")); + m.marshal(o.createHasAccountInBank(object), System.out); + + } + catch ( Exception e ) { + e.printStackTrace(); + } + } + + /** + * Test unmarshalling has bank account Arion 3 + */ + @Test + public void testUnmarshallHasBankAccount() { + try { + final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class); + final Unmarshaller um = context.createUnmarshaller(); + final File file = new File("hasbankaccount.xml"); + final JAXBElement root = um.unmarshal(new StreamSource(file), + HasAccountInBankType.class); + final HasAccountInBankType foo = root.getValue(); + System.out.println(foo.getBankName()); + } + catch ( final JAXBException e ) { + e.printStackTrace(); + } + } } -- cgit v1.2.3