1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.api.readGraph.getPredicates;
14 import java.util.Collection;
15 import java.util.UUID;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.common.utils.NameUtils;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.testing.annotation.Fails;
23 import org.simantics.db.testing.base.WriteReadTest;
24 import org.simantics.db.tests.common.Writes;
27 public class GetPredicatesWithAssertionsTest6 extends WriteReadTest {
29 private Resource type;
30 private Resource type2;
31 private Resource type3;
32 private Resource named1;
33 private Resource named2;
36 protected void write(WriteGraph graph) throws DatabaseException {
38 //type2 = graph.newResource();
39 //graph.claim(type2, L0.Inherits, L0.Entity);
40 //type3 = graph.newResource();
41 //graph.claim(type3, L0.Inherits, L0.Entity);
42 type = graph.newResource();
43 graph.claim(type, L0.Inherits, L0.Entity);
45 //graph.claim(type, L0.Inherits, type2);
46 //graph.claim(type, L0.Inherits, type3);
48 named1 = Writes.named(graph, UUID.randomUUID().toString());
49 named2 = Writes.named(graph, UUID.randomUUID().toString());
51 //graph.claim(type, L0.HasName, named1);
52 //graph.claim(type, L0.ConsistsOf, named2);
55 graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.ConsistsOf, named1));
56 graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, named2));
57 // graph.claim(type, L0.Asserts, Writes.assertion(graph, L0.HasName, named1));
61 protected void read(ReadGraph graph) throws DatabaseException {
63 Collection<Resource> result = graph.getPredicates(type);
64 assertNotNull("Null not allowed", result);
66 for (Resource r: result) {
67 System.out.println("Resrouce: " + NameUtils.getSafeName(graph, r, true));
68 //System.out.println(TestingUtils.predicateName(L0, graph, r));
70 int size = result.size();
71 assertTrue("Wrong number of predicates: " + size,
73 System.out.println(graph.isSubrelationOf(L0.Inherits, L0.DependsOn));
75 //assertTrue(Tests.contains(predicates));
76 //assertTrue(Tests.contains(predicates, L0.SupertypeOf, named2));
81 protected void read(ReadGraph graph) throws DatabaseException {
83 Collection<Statement> consists = graph.getAssertedStatements(type, L0.ConsistsOf);
85 assertTrue(Tests.contains(consists, type, L0.ConsistsOf, named1));
86 assertTrue(Tests.contains(consists, type2, L0.ConsistsOf, named1));
87 assertTrue(Tests.contains(consists, type3, L0.ConsistsOf, named1));
88 assertTrue(consists.size() == 3);