/** * Tests {@link MetadataCopier} on a citation. */ public void testCopy() { final DefaultCitation original = create(); final DefaultCitation clone = (DefaultCitation) new MetadataCopier(MetadataStandard.ISO_19115).copy(original); assertCopy(original, clone); }
/** * Tests XML marshalling using the format derived form ISO 19115:2014 model. * This method also tests usage of {@code gml:id} and {@code xlink:href}. * * @throws JAXBException if an error occurred during marshalling. * * @since 1.0 */ @Test public void testMarshalling() throws JAXBException { testMarshalling(XML2016+FILENAME, VERSION_2014); }
/** * Tests XML unmarshalling using the format derived form ISO 19115:2014 model. * This method also tests usage of {@code gml:id} and {@code xlink:href}. * * @throws JAXBException if an error occurred during unmarshalling. * * @since 1.0 */ @Test public void testUnmarshalling() throws JAXBException { testUnmarshalling(XML2016+FILENAME); }
/** * Tests XML unmarshalling for a metadata version. * The version is not specified since it should be detected automatically. * * @param file file containing the metadata to unmarshal. */ private void testUnmarshalling(final String file) throws JAXBException { final DefaultCitation c = unmarshalFile(DefaultCitation.class, file); assertTitleEquals("title", "Fight against poverty", c); final CitationDate date = getSingleton(c.getDates()); assertEquals("date", date.getDate(), TestUtilities.date("2015-10-17 00:00:00")); assertEquals("dateType", DateType.valueOf("adopted"), date.getDateType()); assertEquals("presentationForm", PresentationForm.valueOf("physicalObject"), getSingleton(c.getPresentationForms())); final Iterator<ResponsibleParty> it = c.getCitedResponsibleParties().iterator(); final Contact contact = assertResponsibilityEquals(Role.ORIGINATOR, "Maid Marian", it.next()); assertEquals("Contact instruction", "Send carrier pigeon.", String.valueOf(contact.getContactInstructions())); final OnlineResource resource = contact.getOnlineResource(); assertEquals("Resource name", "IP over Avian Carriers", String.valueOf(resource.getName())); assertEquals("Resource description", "High delay, low throughput, and low altitude service.", String.valueOf(resource.getDescription())); assertEquals("Resource linkage", "https://tools.ietf.org/html/rfc1149", String.valueOf(resource.getLinkage())); assertEquals("Resource function", OnLineFunction.OFFLINE_ACCESS, resource.getFunction()); // Thanks to xlink:href, the Contact shall be the same instance as above. assertSame("contact", contact, assertResponsibilityEquals(Role.valueOf("funder"), "Robin Hood", it.next())); assertFalse(it.hasNext()); }
/** * Tests the formatting of a {@link DefaultCitation} object. * * @see <a href="https://issues.apache.org/jira/browse/SIS-298">SIS-298</a> */ @Test public void testCitation() { final DefaultCitation citation = DefaultCitationTest.create(); final String text = format.format(citation.asTreeTable()); assertMultilinesEquals( "Citation……………………………………………………………………………… Undercurrent\n" + " ├─Alternate title………………………………………………… Andākarento\n" + " ├─Cited responsible party (1 of 2)\n" + " │ ├─Role…………………………………………………………………… Author\n" + " │ └─Party………………………………………………………………… Testsuya Toyoda\n" + " ├─Cited responsible party (2 of 2)\n" + " │ ├─Role…………………………………………………………………… EDITOR\n" + " │ ├─Extent……………………………………………………………… World\n" + " │ │ └─Geographic element\n" + " │ │ ├─West bound longitude…… 180°W\n" + " │ │ ├─East bound longitude…… 180°E\n" + " │ │ ├─South bound latitude…… 90°S\n" + " │ │ ├─North bound latitude…… 90°N\n" + " │ │ └─Extent type code……………… true\n" + " │ └─Party………………………………………………………………… Kōdansha\n" + " ├─Presentation form (1 of 2)…………………… Document digital\n" + " ├─Presentation form (2 of 2)…………………… Document hardcopy\n" + " └─ISBN……………………………………………………………………………… 9782505004509\n", text); }
/** * Tests XML marshalling for the given metadata version. * * @param file file containing the expected metadata. * @param version the metadata version to marshal. */ private void testMarshalling(final String file, final Version version) throws JAXBException { final DefaultOnlineResource rs = new DefaultOnlineResource(URI.create("https://tools.ietf.org/html/rfc1149")); rs.setName("IP over Avian Carriers"); rs.setDescription(new SimpleInternationalString("High delay, low throughput, and low altitude service.")); rs.setFunction(OnLineFunction.OFFLINE_ACCESS); final DefaultContact contact = new DefaultContact(rs); contact.setContactInstructions(new SimpleInternationalString("Send carrier pigeon.")); contact.getIdentifierMap().putSpecialized(IdentifierSpace.ID, "ip-protocol"); final DefaultCitation c = new DefaultCitation("Fight against poverty"); final DefaultResponsibleParty r1 = new DefaultResponsibleParty(Role.ORIGINATOR); final DefaultResponsibleParty r2 = new DefaultResponsibleParty(Role.valueOf("funder")); r1.setParties(Collections.singleton(new DefaultIndividual("Maid Marian", null, contact))); r2.setParties(Collections.singleton(new DefaultIndividual("Robin Hood", null, contact))); c.setCitedResponsibleParties(Arrays.asList(r1, r2)); c.getDates().add(new DefaultCitationDate(TestUtilities.date("2015-10-17 00:00:00"), DateType.valueOf("adopted"))); c.getPresentationForms().add(PresentationForm.valueOf("physicalObject")); /* * Check that XML file built by the marshaller is the same as the example file. */ assertMarshalEqualsFile(file, c, version, "xmlns:*", "xsi:schemaLocation"); }
getSingleton(clone.getAlternateTitles())); assertCopy(original.getIdentifiers(), clone.getIdentifiers()); assertCopy(original.getCitedResponsibleParties(), clone.getCitedResponsibleParties()); assertCopy(original.getPresentationForms(), clone.getPresentationForms());
/** * Tests {@link DefaultCitation#transition(DefaultCitation.State)} to the final state. */ @Test public void testTransitionToFinal() { final DefaultCitation original = create(); final DefaultCitation clone = create(); clone.transition(DefaultCitation.State.FINAL); assertEquals("original.state", DefaultCitation.State.EDITABLE, original.state()); assertEquals("clone.state", DefaultCitation.State.FINAL, clone.state()); assertEquals(original, clone); SimpleInternationalString title = new SimpleInternationalString("Undercurrent"); original.setTitle(title); try { clone.setTitle(title); fail("Frozen metadata shall not be modifiable."); } catch (UnmodifiableMetadataException e) { // This is the expected exception. } }
/** * Tests {@link DefaultCitation#unmodifiable()}. * * @deprecated To be removed after we removed {@link DefaultCitation#unmodifiable()}. */ @Test @Deprecated public void testUnmodifiable() { final DefaultCitation original = create(); final DefaultCitation clone = (DefaultCitation) original.unmodifiable(); // This will invoke 'freeze()'. assertSame("original.unmodifiable", clone, original.unmodifiable()); assertSame("clone.unmodifiable", clone, clone.unmodifiable()); assertEquals("original.state", DefaultCitation.State.EDITABLE, original.state()); assertEquals("clone.state", DefaultCitation.State.FINAL, clone.state()); assertCopy(original, clone); }
/** * Tests XML marshalling using the format derived form ISO 19115:2003 model. * This method also tests usage of {@code gml:id} and {@code xlink:href}. * * @throws JAXBException if an error occurred during marshalling. * * @since 0.7 */ @Test @DependsOnMethod("testMarshalling") public void testMarshallingLegacy() throws JAXBException { testMarshalling(XML2007+FILENAME, VERSION_2007); }
/** * Tests XML unmarshalling using the format derived form ISO 19115:2003 model. * This method also tests usage of {@code gml:id} and {@code xlink:href}. * * @throws JAXBException if an error occurred during unmarshalling. * * @since 0.7 */ @Test @DependsOnMethod("testUnmarshalling") public void testUnmarshallingLegacy() throws JAXBException { testUnmarshalling(XML2007+FILENAME); }