Package com.clarkparsia.empire.api

Examples of com.clarkparsia.empire.api.TestPerson


  }

  @Test(expected=InvalidRdfException.class)
  public void testInvalidId() throws InvalidRdfException {
    // this should not succeed, null values for the RdfId annotation are not allowed
    RdfGenerator.asRdf(new TestPerson());
  }
View Full Code Here


    }
  }

  @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);
View Full Code Here

    }
  }

  @Test
  public void testRoundTrip() {
    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 aBob = new TestPerson();

    aBob.setBirthday(Dates.asDate("1980-01-01"));
    aBob.setFirstName("Bob");
    aBob.setLastName("Smith");
    aBob.setLikesVideoGames(false);
    aBob.setWeight(200.1f);
    aBob.setWeblogURI(URI.create("http://someblog.example.org"));
    aBob.setTitle("Mr");
    aBob.setMBox("mailto:bob@example.org");

    aBob.getKnows().add(aJoe);
    aBob.getKnows().add(aJane);

    try {
      Graph aGraph = RdfGenerator.asRdf(aBob);

      // this is the set of data that would normally be in the database
      Graph aSourceGraph = new GraphImpl();
      aSourceGraph.addAll(aGraph);
      aSourceGraph.addAll(RdfGenerator.asRdf(aJoe));
      aSourceGraph.addAll(RdfGenerator.asRdf(aJane));

      TestPerson aPerson = RdfGenerator.fromRdf(TestPerson.class, aBob.getRdfId(), new TestDataSource(aSourceGraph));

      assertEquals(aBob, aPerson);

      // now lets test the round trip w/ the added trick of a circular dependency
      aBob.setSpouse(aJane);
View Full Code Here

TOP

Related Classes of com.clarkparsia.empire.api.TestPerson

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.