]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/client/JournalTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / client / JournalTest.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.client;
13
14 import org.junit.Test;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.common.request.WriteRequest;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.request.Read;
21 import org.simantics.db.testing.base.ExistingDatabaseTest;
22 import org.simantics.db.testing.common.TestBase;
23 import org.simantics.layer0.Layer0;
24 public class JournalTest extends ExistingDatabaseTest {
25     private static final int N = 10;
26     private static boolean WRITE = false;
27
28     @Test
29     public void testJournal() throws DatabaseException{
30         write();
31         validate();
32     }
33     private void write()
34     throws DatabaseException {
35         if (!WRITE)
36             return;
37         for (int i=0; i<N; ++i)
38             writeData();
39     }
40     private void writeData()
41     throws DatabaseException {
42         getSession().syncRequest(new WriteRequest() {
43             @Override
44             public void perform(WriteGraph g) throws DatabaseException {
45                 Layer0 b = Layer0.getInstance(g);
46                 Resource root = g.getRootLibrary();
47                 Resource r = g.newResource();
48                 g.claim(root, b.ConsistsOf, null, r);
49             }
50         });
51     }
52     private void validate()
53     throws DatabaseException {
54         for (int i=0; i<N; ++i)
55             validateData();
56     }
57     private void validateData()
58     throws DatabaseException {
59         getSession().syncRequest(new Read<Resource>() {
60             @Override
61             public Resource perform(ReadGraph g) throws DatabaseException {
62                 Layer0 l0 = Layer0.getInstance(g);
63                 Resource root = g.getResource(TestBase.ROOT_LIBRARY_URI);
64                 for (Resource r : g.getObjects(root, l0.ConsistsOf))
65                     if (DEBUG)
66                         System.out.println("Resource " + r);
67                 return null;
68             }
69             
70         });
71     }
72 }