}
}
@Test
public void testConvert() throws Exception {
TestPerson aJoe = new TestPerson();
aJoe.setMBox("mailto:joe@example.org");
aJoe.setFirstName("Joe");
TestPerson aJane = new TestPerson();
aJane.setMBox("mailto:jane@example.org");
aJane.setFirstName("Jane");
TestPerson aPerson = new TestPerson();
aPerson.setMBox("mailto:bob@example.org");
try {
ExtGraph aGraph = Graphs.extend(RdfGenerator.asRdf(aPerson));
org.openrdf.model.URI aPersonURI = aGraph.getValueFactory().createURI(aPerson.getRdfId().toString());
assertEquals(aGraph.size(), 2);
// the statements should assert that the person is of type foaf:TestPerson
assertTrue(Sets.newHashSet(aGraph.getTypes(aPersonURI)).contains(FOAF.ontology().Person));
// and that the mbox is correct
assertEquals(Graphs.getLiteral(aGraph, aPersonURI, FOAF.ontology().mbox).get().getLabel(), aPerson.getMBox());
// now lets try with some more properties
aPerson.setWeight(123.45f);
aPerson.setBirthday(new Date());
aPerson.setFirstName("John");
aPerson.setLastName("Doe");
aPerson.setLikesVideoGames(true);
aPerson.setTitle("Sir");
aPerson.getKnows().add(aJoe);
aPerson.getKnows().add(aJane);
aPerson.setWeblogURI(URI.create("http://example.org"));
aGraph = Graphs.extend(RdfGenerator.asRdf(aPerson));
assertEquals((Float) Float.parseFloat(aGraph.getLiteral(aPersonURI, TestVocab.ontology().weight).get().getLabel()),
aPerson.getWeight());
// this tests if "inferring" from an annotated getter works
assertEquals(Boolean.valueOf(aGraph.getLiteral(aPersonURI, TestVocab.ontology().likesVideoGames).get().getLabel()),
aPerson.isLikesVideoGames());
// and this tests if 'inferring" from an annotated setter works
// also checking that it properly used the other namespace
assertEquals(aGraph.getLiteral(aPersonURI, DC.ontology().title).get().getLabel(),
aPerson.getTitle());
assertEquals(URI.create(GraphUtil.getUniqueObject(aGraph, aPersonURI, DC.ontology().publisher).stringValue()),
aPerson.getWeblogURI());
assertEquals(aGraph.getLiteral(aPersonURI, FOAF.ontology().firstName).get().getLabel(),
aPerson.getFirstName());
assertEquals(aGraph.getLiteral(aPersonURI, FOAF.ontology().surname).get().getLabel(),
aPerson.getLastName());
assertEquals(aGraph.getLiteral(aPersonURI, RDFS.LABEL).get().getLabel(),
aPerson.getLabel());
List aKnows = Lists.newArrayList(GraphUtil.getObjects(aGraph, aPersonURI, FOAF.ontology().knows));
assertEquals(aKnows.size(), 2);