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.UUID;
16 import org.junit.Test;
17 import org.simantics.databoard.Bindings;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Session;
20 import org.simantics.db.VirtualGraph;
21 import org.simantics.db.WriteGraph;
22 import org.simantics.db.common.request.WriteRequest;
23 import org.simantics.db.common.request.WriteResultRequest;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.service.VirtualGraphSupport;
26 import org.simantics.db.testing.base.TestCleanDb;
27 import org.simantics.layer0.Layer0;
29 public class VirtualGraphTest extends TestCleanDb {
31 private Error exception;
34 public void test() throws DatabaseException {
36 Session session = getSession();
38 session.syncRequest(new WriteRequest() {
41 public void perform(WriteGraph graph) throws DatabaseException {
43 Layer0 L0 = Layer0.getInstance(graph);
45 final Resource newResource = graph.syncRequest(new WriteResultRequest<Resource>() {
48 public Resource perform(WriteGraph graph) throws DatabaseException {
50 Layer0 L0 = Layer0.getInstance(graph);
51 Resource result = graph.newResource();
52 graph.addLiteral(result, L0.HasName, L0.NameOf, L0.String, "RootLibrary", Bindings.STRING);
59 String rootName = graph.getRelatedValue(newResource, L0.HasName);
60 if(!rootName.equals("RootLibrary")) {
61 exception = new AssertionError("rootName != 'RootLibrary'");
65 VirtualGraphSupport support = graph.getSession().getService(VirtualGraphSupport.class);
66 final VirtualGraph virtual = support.getMemoryPersistent(UUID.randomUUID().toString());
68 graph.syncRequest(new WriteRequest(virtual) {
71 public void perform(WriteGraph graph) throws DatabaseException {
73 Layer0 L0 = Layer0.getInstance(graph);
74 graph.addLiteral(newResource, L0.HasName, L0.NameOf, L0.String, "RootLibrary2", Bindings.STRING);
80 rootName = graph.getRelatedValue(newResource, L0.HasName);
81 if(!rootName.equals("RootLibrary2")) {
82 exception = new AssertionError("rootName != 'RootLibrary2'");
86 support.discard(virtual);
88 rootName = graph.getRelatedValue(newResource, L0.HasName);
89 if(!rootName.equals("RootLibrary")) {
90 exception = new AssertionError("rootName != 'RootLibrary'");
98 if(exception != null) {
99 fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");