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.client;
14 import java.util.Collection;
16 import org.junit.Test;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Session;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.common.request.ReadRequest;
22 import org.simantics.db.common.request.WriteRequest;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.exception.ValidationException;
25 import org.simantics.db.testing.annotation.Fails;
26 import org.simantics.db.testing.common.TestBase;
27 import org.simantics.db.testing.common.Tests;
28 import org.simantics.db.testing.impl.Configuration;
29 import org.simantics.layer0.Layer0;
31 public class ConnectionTest4 {
32 private static final int RECONNECT_COUNT = Configuration.get().connectionReconnectCount;
33 private static final boolean SKIP = Configuration.get().skipServerCreation;
34 private Session session = null;
37 public void test4() throws DatabaseException {
39 System.out.println("This test is not valid for remote server.");
42 for (int i=0; i<RECONNECT_COUNT; ++i) {
46 void connectionTest() throws DatabaseException {
48 session = Tests.getTestHandler().getSession();
49 final String newInstanceName ="ConnectionTest4InstanceName-" +
50 TestBase.getRandomString();
52 session.syncRequest(new WriteRequest() {
54 public void perform(WriteGraph g) throws DatabaseException {
55 Layer0 b = Layer0.getInstance(g);
56 Resource newResource = g.newResource();
57 g.claim(newResource, b.InstanceOf, null, b.Type);
58 g.claimLiteral(newResource, b.HasName, newInstanceName);
59 g.claim(g.getRootLibrary(), b.ConsistsOf, newResource);
63 session.syncRequest(new ReadRequest() {
65 public void run(ReadGraph g) throws DatabaseException {
66 Layer0 b = Layer0.getInstance(g);
67 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
68 Resource newResource = null;
69 for (Resource r : resources) {
70 String value = g.getPossibleRelatedValue(r, b.HasName);
71 if (null != value && value.equals(newInstanceName)) {
76 if (newResource == null) {
77 throw new ValidationException("Could not find created resource");
79 if (!g.isInstanceOf(newResource, b.Type))
80 throw new ValidationException("Created resource is not an instance of Type");
83 Tests.closeSession(session);
84 session = Tests.getTestHandler().getSession();
85 session.syncRequest(new ReadRequest() {
87 public void run(ReadGraph g) throws DatabaseException {
88 Layer0 b = Layer0.getInstance(g);
89 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
90 Resource newResource = null;
91 for (Resource r : resources) {
92 String value = g.getPossibleRelatedValue(r, b.HasName);
93 if (null != value && value.equals(newInstanceName)) {
98 if (newResource == null) {
99 throw new ValidationException("Could not find created resource");
101 if (!g.isInstanceOf(newResource, b.Type))
102 throw new ValidationException("Created resource is not an instance of Type");
105 Tests.closeSession(session);
106 // } catch (ClassNotFoundException e) {
107 // throw new DatabaseException("Test failed.", e);
109 Tests.closeSession(session);