コード例 #1
0
  @Test
  public void testDelete() {
    ds.begin(ReadWrite.WRITE);
    try {
      Ontology ont = Ontology.loadOntology(ds, testOntologyName);
      OntologyInstance instance = ont.getInstance(deleteInstanceId);

      instance.delete();

      assertTrue("", instance.getJSONRepresentation().length() == 0);

      ds.commit();
    } finally {
      ds.end();
    }

    ds.begin(ReadWrite.READ);
    try {
      Ontology ont = Ontology.loadOntology(ds, testOntologyName);
      ont.getInstance(deleteInstanceId);

      fail("Should throw RuntimeException when getting deleted Instance");
    } catch (RuntimeException e) {
    } finally {
      ds.end();
    }
  }
コード例 #2
0
  @Test
  public void testUpdate() {

    ds.begin(ReadWrite.WRITE);
    try {
      Ontology ont = Ontology.loadOntology(ds, testOntologyName);

      JSONObject values = new JSONObject();

      OntologyInstance instance = ont.createInstance(simpleClassId, values);

      JSONObject rep = instance.getJSONRepresentation();

      assertTrue(rep.length() == 0);

      // Add DataProperty

      values.put(idChar + dataPropId, new JSONArray("[test]"));

      instance.update(values);

      rep = instance.getJSONRepresentation();

      assertTrue(rep.length() == 1);
      assertTrue(rep.toString().equals(values.toString()));

      ds.commit();
    } catch (JSONException e) {
      ds.abort();
      fail(e.getMessage());
    } finally {
      ds.end();
    }
  }
コード例 #3
0
  @Test
  public void test_CreateSimpleWithObjectProp() {
    String classId = simpleClassId;

    ds.begin(ReadWrite.WRITE);
    try {
      Ontology ont = Ontology.loadOntology(ds, testOntologyName);
      JSONObject values = new JSONObject();

      String[] propValue = new String[1];
      propValue[0] = existingInstanceId;
      values.put(idChar + objectPropId, new JSONArray(propValue));

      OntologyInstance instance = ont.createInstance(classId, values);

      JSONObject rep = instance.getJSONRepresentation();

      assertTrue("JSON Rep: " + rep, rep.length() == values.length());
      assertTrue(
          "Instance does not have expected data property and value: " + rep,
          rep.has(idChar + objectPropId)
              && rep.optJSONArray(idChar + objectPropId).length() == 1
              && rep.optJSONArray(idChar + objectPropId).optString(0).equals(propValue[0]));
      ds.commit();
    } catch (JSONException e) {
      ds.abort();
      fail(e.getMessage());
    } finally {
      ds.end();
    }
  }
コード例 #4
0
  @Test
  public void testRead() {

    ds.begin(ReadWrite.READ);
    try {
      Ontology ont = Ontology.loadOntology(ds, testOntologyName);

      OntologyInstance instance = ont.getInstance(existingInstanceId);

      JSONObject rep = instance.getJSONRepresentation();

      assertTrue("", rep.length() == 0);
    } finally {
      ds.end();
    }
  }
コード例 #5
0
  @Test
  public void test_CreateSimple() {
    String classId = simpleClassId;

    ds.begin(ReadWrite.WRITE);
    try {
      Ontology ont = Ontology.loadOntology(ds, testOntologyName);

      JSONObject values = new JSONObject();

      OntologyInstance instance = ont.createInstance(classId, values);

      JSONObject rep = instance.getJSONRepresentation();

      assertTrue(rep.toString(), rep.length() == values.length());

      ds.commit();
    } finally {
      ds.end();
    }
  }