PeriodicalIssueMapper implements Mapper<PeriodicalIssue> { @Override public PeriodicalIssue map(ModsDefinition mods) { NodeLookup nlookup = new NodeLookup(mods); PeriodicalIssue issue = new PeriodicalIssue(); issue.setIdentifiers(identMap.map(mods)); DateDefinition date = nlookup.getDate(false); issue.setIssueDate(date == null ? null : date.getValue()); Text note = nlookup.getNote(false); issue.setNote(note == null ? null : note.getValue()); issue.setIssueNumber(MapperUtils.toString(nlookup.getNumber(false))); issue.setIssueSortingNumber(MapperUtils.toString(nlookup.getSortingNumber(false))); return issue; }  @Override PeriodicalIssue map(ModsDefinition mods); @Override ModsDefinition map(ModsDefinition mods, PeriodicalIssue issue);  }
@Test public void testRead() throws Exception { ModsDefinition mods = ModsUtils.unmarshal(PeriodicalIssueMapperTest.class.getResource("issue_mods.xml"), ModsDefinition.class); PeriodicalIssueMapper instance = new PeriodicalIssueMapper(); PeriodicalIssue result = instance.map(mods); assertNotNull(result); assertEquals("1", result.getIssueNumber()); assertEquals("2", result.getIssueSortingNumber()); assertEquals("16.12.1893", result.getIssueDate()); assertEquals("note", result.getNote()); }
@Test public void testWriteRead() throws Exception { ModsDefinition mods = new ModsDefinition(); PeriodicalIssue value = new PeriodicalIssue(); value.setIssueNumber("1"); value.setIssueSortingNumber("2"); value.setIssueDate("16.12.1893"); value.setNote("note"); value.setIdentifiers(Arrays.asList(new IdentifierMapper.IdentifierItem(null, "uuid", "1"))); PeriodicalIssueMapper instance = new PeriodicalIssueMapper(); instance.map(mods, value); String dump = ModsUtils.toXml(mods, true); PeriodicalIssue result = instance.map(ModsUtils.unmarshal(dump, ModsDefinition.class)); assertNotNull(result); assertEquals(value.getIssueSortingNumber(), result.getIssueNumber()); assertEquals(value.getIssueSortingNumber(), result.getIssueSortingNumber()); assertEquals(value.getIssueDate(), result.getIssueDate()); assertEquals(value.getNote(), result.getNote()); assertEquals(Arrays.asList(new IdentifierItem(0, "uuid", "1")), result.getIdentifiers()); }