DocumentMetadataConverter implements OafEntityToAvroConverter<Result, DocumentMetadata> { @Override public DocumentMetadata convert(Result result) throws IOException { Preconditions.checkNotNull(result); DocumentMetadata.Builder builder = DocumentMetadata.newBuilder(); builder.setId(result.getId()); createBasicMetadata(result, builder); handleAdditionalIds(result, builder); handleDatasourceIds(result, builder); handlePersons(result, builder); return builder.build(); } DocumentMetadataConverter(FieldApprover fieldApprover); @Override DocumentMetadata convert(Result result);  }
@Test(expected=NullPointerException.class) public void convert_null_oafEntity() throws IOException { converter.convert(null); }
@Test public void convert_using_main_title() throws IOException { Publication publication = minimalEntityBuilder(ID, InfoSpaceConstants.SEMANTIC_CLASS_INSTANCE_TYPE_ARTICLE); addTitle(publication, OTHER_TITLE); addTitle(publication, TITLE, InfoSpaceConstants.SEMANTIC_CLASS_MAIN_TITLE); DocumentMetadata metadata = converter.convert(publication); assertEquals(TITLE, metadata.getTitle()); }
@Test public void convert_using_null_main_title_and_not_null_other_title() throws IOException { Publication publication = minimalEntityBuilder(ID, InfoSpaceConstants.SEMANTIC_CLASS_INSTANCE_TYPE_ARTICLE); addTitle(publication, OTHER_TITLE); addTitle(publication, null, InfoSpaceConstants.SEMANTIC_CLASS_MAIN_TITLE); DocumentMetadata metadata = converter.convert(publication); assertEquals(OTHER_TITLE, metadata.getTitle()); }
@Test public void convert_using_first_title() throws IOException { Publication publication = minimalEntityBuilder(ID, InfoSpaceConstants.SEMANTIC_CLASS_INSTANCE_TYPE_ARTICLE); addTitle(publication, OTHER_TITLE); addTitle(publication, TITLE); DocumentMetadata metadata = converter.convert(publication); assertEquals(OTHER_TITLE, metadata.getTitle()); }
@Test public void convert_null_date_of_acceptance() throws IOException { Publication oafEntity = documentEntity(); oafEntity.getDateofacceptance().setValue(null); DocumentMetadata metadata = converter.convert(oafEntity); assertNotNull(metadata); assertEquals(ID, metadata.getId()); assertNull(metadata.getYear()); }
@Test public void convert_skip_null_abstract() throws IOException { Publication publication = minimalEntityBuilder(ID, InfoSpaceConstants.SEMANTIC_CLASS_INSTANCE_TYPE_ARTICLE); addDescription(publication, "null"); addDescription(publication, ABSTRACT); DocumentMetadata metadata = converter.convert(publication); assertEquals(ABSTRACT, metadata.getAbstract$()); }
@Test public void convert_with_undefined_language() throws IOException { Publication publication = minimalEntityBuilder(ID, InfoSpaceConstants.SEMANTIC_CLASS_INSTANCE_TYPE_ARTICLE); setLanguage(publication, "und"); DocumentMetadata metadata = converter.convert(publication); assertEquals(null, metadata.getLanguage()); }
@Test public void convert_not_approved() throws IOException { Publication oafEntity = documentEntity(); when(fieldApprover.approve(any())).thenReturn(false); DocumentMetadata metadata = converter.convert(oafEntity); assertEquals(ID, metadata.getId()); assertEquals(null, metadata.getTitle()); assertEquals(null, metadata.getAbstract$()); assertEquals(LANGUAGE, metadata.getLanguage()); assertEquals(null, metadata.getKeywords()); assertEquals(null, metadata.getExternalIdentifiers()); assertEquals(null, metadata.getJournal()); assertEquals(null, metadata.getYear()); assertEquals(null, metadata.getPublisher()); assertTrue(metadata.getPublicationType().getArticle()); assertTrue(metadata.getPublicationType().getDataset()); assertEquals(DATASOURCE_IDS, metadata.getDatasourceIds()); assertEquals(1, metadata.getAuthors().size()); assertEquals(FIRST_NAME, metadata.getAuthors().get(0).getName()); assertEquals(SECOND_NAME + ' ' + SECOND_SECOND_NAME, metadata.getAuthors().get(0).getSurname()); assertEquals(FULL_NAME, metadata.getAuthors().get(0).getFullname()); }
@Test public void convert() throws IOException { Publication oafEntity = documentEntity(); DocumentMetadata metadata = converter.convert(oafEntity); assertEquals(ID, metadata.getId()); assertEquals(TITLE, metadata.getTitle()); assertEquals(ABSTRACT, metadata.getAbstract$()); assertEquals(LANGUAGE, metadata.getLanguage()); assertEquals(KEYWORDS, metadata.getKeywords()); assertEquals(EXT_IDENTIFIERS, metadata.getExternalIdentifiers()); assertEquals(JOURNAL, metadata.getJournal()); assertEquals(YEAR, metadata.getYear()); assertEquals(PUBLISHER, metadata.getPublisher()); assertTrue(metadata.getPublicationType().getArticle()); assertTrue(metadata.getPublicationType().getDataset()); assertEquals(1, metadata.getAuthors().size()); assertEquals(FIRST_NAME, metadata.getAuthors().get(0).getName()); assertEquals(SECOND_NAME + ' ' + SECOND_SECOND_NAME, metadata.getAuthors().get(0).getSurname()); assertEquals(FULL_NAME, metadata.getAuthors().get(0).getFullname()); assertEquals(DATASOURCE_IDS, metadata.getDatasourceIds()); }