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.support.virtualGraphSupport;
14 import java.util.Arrays;
15 import java.util.HashSet;
16 import java.util.UUID;
18 import org.junit.Test;
19 import org.simantics.databoard.Bindings;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Session;
22 import org.simantics.db.VirtualGraph;
23 import org.simantics.db.WriteGraph;
24 import org.simantics.db.common.request.WriteRequest;
25 import org.simantics.db.exception.DatabaseException;
26 import org.simantics.db.service.VirtualGraphSupport;
27 import org.simantics.db.testing.base.TestCleanDb;
28 import org.simantics.layer0.Layer0;
30 public class VirtualGraphTest2 extends TestCleanDb {
32 private Error exception;
35 public void test() throws DatabaseException {
37 Session session = getSession();
38 VirtualGraphSupport support = session.getService(VirtualGraphSupport.class);
39 final VirtualGraph virtual = support.getMemoryPersistent(UUID.randomUUID().toString());
41 session.syncRequest(new WriteRequest() {
44 public void perform(WriteGraph g) throws DatabaseException {
46 Layer0 b = Layer0.getInstance(g);
48 final HashSet<String> strings = new HashSet<String>();
50 for(Resource r : g.getObjects(g.getRootLibrary() , b.ConsistsOf)) {
51 String name = g.getPossibleRelatedValue(r, b.HasName);
55 g.syncRequest(new WriteRequest(virtual) {
58 public void perform(WriteGraph g) throws DatabaseException {
60 Layer0 b = Layer0.getInstance(g);
61 for(int i=0;i<10;i++) {
62 Resource r = g.newResource();
63 String name = "Virtual" + i;
64 g.claimLiteral(r, b.HasName, name, Bindings.STRING);
66 g.claim(g.getRootLibrary(), b.ConsistsOf, r);
73 for(Resource r : g.getObjects(g.getRootLibrary() , b.ConsistsOf)) {
74 String name = g.getPossibleRelatedValue(r, b.HasName);
76 System.out.println("found " + name);
77 boolean success = strings.remove(name);
79 exception = new AssertionError("encountered unknown string " + name);
84 if(!strings.isEmpty()) {
85 exception = new AssertionError("some strings were left over " + Arrays.toString(strings.toArray()));
93 if(exception != null) {
94 fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");