X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fsupport%2FvirtualGraphSupport%2FVirtualGraphTest.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fsupport%2FvirtualGraphSupport%2FVirtualGraphTest.java;h=4ff12d68f8ab6af173f4d28ee7dcc4b1ae61c7cb;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest.java new file mode 100644 index 000000000..4ff12d68f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphTest.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.virtualGraphSupport; + +import java.util.UUID; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.TestCleanDb; +import org.simantics.layer0.Layer0; + +public class VirtualGraphTest extends TestCleanDb { + + private Error exception; + + @Test + public void test() throws DatabaseException { + + Session session = getSession(); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + + final Resource newResource = graph.syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Resource result = graph.newResource(); + graph.addLiteral(result, L0.HasName, L0.NameOf, L0.String, "RootLibrary", Bindings.STRING); + return result; + + } + + }); + + String rootName = graph.getRelatedValue(newResource, L0.HasName); + if(!rootName.equals("RootLibrary")) { + exception = new AssertionError("rootName != 'RootLibrary'"); + throw exception; + } + + VirtualGraphSupport support = graph.getSession().getService(VirtualGraphSupport.class); + final VirtualGraph virtual = support.getMemoryPersistent(UUID.randomUUID().toString()); + + graph.syncRequest(new WriteRequest(virtual) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + graph.addLiteral(newResource, L0.HasName, L0.NameOf, L0.String, "RootLibrary2", Bindings.STRING); + + } + + }); + + rootName = graph.getRelatedValue(newResource, L0.HasName); + if(!rootName.equals("RootLibrary2")) { + exception = new AssertionError("rootName != 'RootLibrary2'"); + throw exception; + } + + support.discard(virtual); + + rootName = graph.getRelatedValue(newResource, L0.HasName); + if(!rootName.equals("RootLibrary")) { + exception = new AssertionError("rootName != 'RootLibrary'"); + throw exception; + } + + } + + }); + + if(exception != null) { + fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through "); + } + + } + +}