]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/virtualGraphSupport/VirtualGraphSupportListStatementsTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / support / virtualGraphSupport / VirtualGraphSupportListStatementsTest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.api.support.virtualGraphSupport;
13
14 import java.util.Collection;
15 import java.util.UUID;
16
17 import org.junit.Test;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Statement;
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.ExistingDatabaseTest;
27
28 public class VirtualGraphSupportListStatementsTest extends ExistingDatabaseTest {
29         
30         @Test
31         public void test() throws Exception{
32
33                 // Create a new persistent resource
34                 final Resource resource = getSession().syncRequest(new WriteResultRequest<Resource>() {
35                     @Override
36                     public Resource perform(WriteGraph g) throws DatabaseException {
37                         return g.newResource();
38                     }
39                 });
40                 
41                 VirtualGraphSupport vgs = getSession().getService(VirtualGraphSupport.class);
42                 VirtualGraph vg = vgs.getMemoryPersistent(UUID.randomUUID().toString());
43                 
44                 // Create some virtual graph
45                 getSession().syncRequest(new WriteRequest(vg) {
46                     @Override
47                     public void perform(WriteGraph graph) throws DatabaseException {
48                         Resource virtual = graph.newResource();
49                         graph.claim(resource, L0.ConsistsOf, virtual);
50                         graph.claimLiteral(virtual, L0.HasName, "Name");
51                         
52                     }
53                 });
54                 
55                 checkException();
56                 
57                 Collection<Statement> stms = vgs.listStatements(vg);
58         
59                 assertEquals("Amount of statements.", stms.size(), 5);
60                 
61         }
62
63 }