예제 #1
0
  @Test
  public void test1() throws Exception {

    InputStream fis = getClass().getResourceAsStream("../mappingFiles/test5.ttl");

    JenaR2RMLMappingManager mm = JenaR2RMLMappingManager.getInstance();

    Model m = ModelFactory.createDefaultModel();
    m = m.read(fis, "testMapping", "TURTLE");
    Collection<TriplesMap> coll = mm.importMappings(m);

    Assert.assertTrue(coll.size() == 1);

    Iterator<TriplesMap> it = coll.iterator();
    while (it.hasNext()) {
      TriplesMap current = it.next();

      SubjectMap s = current.getSubjectMap();
      Template t = s.getTemplate();
      Assert.assertTrue(t.getColumnName(0).contains("EMPNO"));

      LogicalTable table = current.getLogicalTable();

      SQLBaseTableOrViewImpl ta = (SQLBaseTableOrViewImpl) table;
      Assert.assertTrue(ta.getTableName().contains("EMP2DEPT"));
    }
  }
예제 #2
0
  @Test
  public void test() throws Exception {
    InputStream fis = getClass().getResourceAsStream("../mappingFiles/test25.ttl");

    RDF4JR2RMLMappingManager mm = RDF4JR2RMLMappingManager.getInstance();

    // Read the file into a model.
    RDFParser rdfParser = Rio.createParser(RDFFormat.N3);
    Model m = new LinkedHashModel();
    rdfParser.setRDFHandler(new StatementCollector(m));
    rdfParser.parse(fis, "testMapping");

    Collection<TriplesMap> coll = mm.importMappings(m);

    Assert.assertTrue(coll.size() == 2);

    Iterator<TriplesMap> it = coll.iterator();
    while (it.hasNext()) {
      TriplesMap current = it.next();

      Iterator<PredicateObjectMap> pomit = current.getPredicateObjectMaps().iterator();
      int cont = 0;
      while (pomit.hasNext()) {
        pomit.next();
        cont++;
      }

      if (cont == 1) { // we are analyzing the TriplesMap2
        SubjectMap s = current.getSubjectMap();
        Iterator<GraphMap> gmit = s.getGraphMaps().iterator();

        int conta = 0;
        while (gmit.hasNext()) {
          GraphMap g = gmit.next();
          Assert.assertTrue(g.getConstant().contains("http://example.com/graph/sports"));
          conta++;
        }
        Assert.assertTrue(conta == 1);
      } else { // we are analyzing the TriplesMap1
        Assert.assertTrue(cont == 2);

        pomit = current.getPredicateObjectMaps().iterator();

        while (pomit.hasNext()) {
          PredicateObjectMap pom = pomit.next();

          Iterator<GraphMap> gmit = pom.getGraphMaps().iterator();

          int contt = 0;
          while (gmit.hasNext()) {
            GraphMap g = gmit.next();
            boolean result = g.getConstant().contains("http://example.com/graph/practise");
            boolean result1 = g.getConstant().contains("http://example.com/graph/students");

            Assert.assertTrue(result || result1);
            contt++;
          }

          Assert.assertTrue(contt == 1);

          Iterator<RefObjectMap> romit = pom.getRefObjectMaps().iterator();
          while (romit.hasNext()) {
            RefObjectMap rom = romit.next();

            Assert.assertTrue(rom.getParentMap() != null);

            Iterator<Join> itjoin = rom.getJoinConditions().iterator();

            int joincont = 0;
            while (itjoin.hasNext()) {
              itjoin.next();
              joincont++;
            }
            Assert.assertTrue(joincont == 1);
          }
        }
      }
    }
  }