]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue2967Test1.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / regression / bugs / Issue2967Test1.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.regression.bugs;
13
14 import java.util.Collection;
15 import java.util.UUID;
16
17 import org.junit.Test;
18 import org.simantics.databoard.Bindings;
19 import org.simantics.db.Resource;
20 import org.simantics.db.Session;
21 import org.simantics.db.VirtualGraph;
22 import org.simantics.db.WriteGraph;
23 import org.simantics.db.common.request.WriteRequest;
24 import org.simantics.db.common.request.WriteResultRequest;
25 import org.simantics.db.exception.DatabaseException;
26 import org.simantics.db.service.VirtualGraphSupport;
27 import org.simantics.db.testing.annotation.Fails;
28 import org.simantics.db.testing.cases.FreshDatabaseTest;
29 import org.simantics.layer0.Layer0;
30 import org.simantics.utils.DataContainer;
31
32 public class Issue2967Test1 extends FreshDatabaseTest {
33         
34     private int N_RESOURCE = 10000;  
35     private int N_STM = 100;
36     
37         @Test
38         @Fails
39     public void test() throws DatabaseException {
40         Session session = getSession();
41         session.syncRequest(new WriteRequest() {
42             @Override
43             public void perform(WriteGraph graph) throws DatabaseException {
44                 Layer0 L0 = Layer0.getInstance(graph);
45                 final Resource newResource = graph.syncRequest(new WriteResultRequest<Resource>() {
46                     @Override
47                     public Resource perform(WriteGraph graph) throws DatabaseException {
48                         Layer0 L0 = Layer0.getInstance(graph);
49                         Resource result = graph.newResource();
50                         graph.addLiteral(result, L0.HasName, L0.NameOf, L0.String, "RootLibrary", Bindings.STRING);
51                         Resource root = graph.getRootLibrary();
52                         graph.claim(root, L0.ConsistsOf, result);
53                         return result;
54                     }
55                 });
56                 String rootName = graph.getRelatedValue(newResource, L0.HasName);
57                 assertTrue("Failed to set resource name.", rootName.equals("RootLibrary"));
58                 VirtualGraphSupport support = graph.getSession().getService(VirtualGraphSupport.class);
59                 final String name = UUID.randomUUID().toString();
60                 final VirtualGraph virtual = support.getMemoryPersistent(name);
61                 graph.syncRequest(new WriteRequest(virtual) {
62                     @Override
63                     public void perform(WriteGraph graph) throws DatabaseException {
64                         Layer0 L0 = Layer0.getInstance(graph);
65                         for (int i=0; i<N_RESOURCE; ++i) {
66                             Resource r = graph.newResource();
67                             graph.addLiteral(r, L0.HasName, L0.NameOf, L0.String, "Resource" + i, Bindings.STRING);
68                             graph.claim(newResource, L0.ConsistsOf, r);
69                             for (int j=0; j<N_STM; ++j) {
70                                 Resource rr = graph.newResource();
71                                 graph.claim(rr, L0.InstanceOf, L0.Entity);
72                                 graph.claim(r, L0.HasComment, rr);
73                             }
74                         }
75                     }
76                 });
77                 final DataContainer<Boolean> ok = new DataContainer<Boolean>();
78                 ok.set(false);
79                 Collection<Resource> resources = graph.getObjects(newResource, L0.ConsistsOf);
80                 if (resources.size() != N_RESOURCE)
81                     fail("Virtual graph data has changed. Object size mismatch. size=" + resources.size());
82                 for (Resource r : resources) {
83                     Collection<Resource> ress = graph.getObjects(r, L0.HasComment);
84                     assertEquals("Virtual graph has changed.", N_STM, ress.size());
85                 }
86                 graph.syncRequest(new WriteRequest(virtual) {
87                     @Override
88                     public void perform(WriteGraph graph) throws DatabaseException {
89                         for (int i=0; i<N_RESOURCE; ++i) {
90                             Resource r = graph.getResource("http://RootLibrary/Resource" + i);
91                             assertNotNull("Failed to find created resource.", r);
92                         }
93                         ok.set(true);
94                     }
95                 });
96                 assertEquals("Virtual graph data has changed.", true, (boolean)ok.get());
97             }
98         });
99     }
100
101 }