OrganizationConverter implements OafEntityToAvroConverter<eu.dnetlib.dhp.schema.oaf.Organization, Organization> { @Override public Organization convert(eu.dnetlib.dhp.schema.oaf.Organization srcOrganization) { Preconditions.checkNotNull(srcOrganization); if (!isDataCorrect(srcOrganization)) { return null; } Organization.Builder orgBuilder = Organization.newBuilder(); orgBuilder.setId(srcOrganization.getId()); orgBuilder.setName(srcOrganization.getLegalname().getValue()); orgBuilder.setShortName(srcOrganization.getLegalshortname() != null ? srcOrganization.getLegalshortname().getValue() : null); orgBuilder.setCountryName(srcOrganization.getCountry() != null ? srcOrganization.getCountry().getClassname() : null); orgBuilder.setCountryCode(srcOrganization.getCountry() != null ? srcOrganization.getCountry().getClassid() : null); orgBuilder.setWebsiteUrl(srcOrganization.getWebsiteurl() != null ? srcOrganization.getWebsiteurl().getValue(): null); return orgBuilder.build(); }  @Override Organization convert(eu.dnetlib.dhp.schema.oaf.Organization srcOrganization);  }
@Test(expected = NullPointerException.class) public void buildObject_resolvedOadObject_NULL() throws Exception { converter.convert(null); }
@Test public void buildObject_organization_metadata_name_empty() throws Exception { eu.dnetlib.dhp.schema.oaf.Organization organization = createEmptyOafObject(); assertNull(converter.convert(organization)); verify(log).error("skipping: empty organization name"); }
@Test public void buildObject() throws Exception { Qualifier country = new Qualifier(); country.setClassid("PL"); country.setClassname("Poland"); eu.dnetlib.dhp.schema.oaf.Organization organization = createOafObject(country, createStringField("Interdyscyplinary Centre"), createStringField("ICM"), createStringField("www.icm.edu.pl")); Organization org = converter.convert(organization); assertNotNull(org); assertEquals("Interdyscyplinary Centre", org.getName()); assertEquals("ICM", org.getShortName()); assertEquals("Poland", org.getCountryName()); assertEquals("PL", org.getCountryCode()); assertEquals("www.icm.edu.pl", org.getWebsiteUrl()); verifyZeroInteractions(log); }
@Test public void buildObject_legal_short_name_null() throws Exception { Qualifier country = new Qualifier(); country.setClassid("PL"); country.setClassname("Poland"); eu.dnetlib.dhp.schema.oaf.Organization organization = createOafObject(country, createStringField("Interdyscyplinary Centre"), null, createStringField("www.icm.edu.pl")); Organization org = converter.convert(organization); assertNotNull(org); assertEquals("Interdyscyplinary Centre", org.getName()); assertNull(org.getShortName()); assertEquals("Poland", org.getCountryName()); assertEquals("PL", org.getCountryCode()); assertEquals("www.icm.edu.pl", org.getWebsiteUrl()); verifyZeroInteractions(log); }