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.WriteRequest;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.exception.ValidationException;
24 import org.simantics.db.service.LifecycleSupport;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26 import org.simantics.db.testing.common.Tests;
27 import org.simantics.db.testing.impl.Configuration;
28 import org.simantics.layer0.Layer0;
30 public class ConnectionTest1 extends ExistingDatabaseTest {
31 // private static final String USERNAME = Configuration.get().username;
32 // private static final String PASSWORD = Configuration.get().password;
33 private static final int RECONNECT_COUNT = Configuration.get().connectionReconnectCount;
36 public void test1() throws DatabaseException {
37 Session session = null;
38 for (int i=0; i<RECONNECT_COUNT; ++i) {
39 connectionTest(session);
42 void connectionTest(Session session) throws DatabaseException {
44 session = Tests.getTestHandler().getSession();
45 boolean TEST_QUERY = true;
47 final String newInstanceName ="ConnectionTest1InstanceName-" +
49 session.syncRequest(new WriteRequest() {
51 public void perform(WriteGraph g) throws DatabaseException {
52 Layer0 b = Layer0.getInstance(g);
53 Resource newResource = g.newResource();
54 g.claim(newResource, b.InstanceOf, null, b.Type);
55 g.claimLiteral(newResource, b.HasName, newInstanceName);
56 g.claim(g.getRootLibrary(), b.ConsistsOf, newResource);
60 session.syncRequest(new TestReadRequest() {
62 public void run(ReadGraph g) throws DatabaseException {
63 Layer0 b = Layer0.getInstance(g);
64 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
65 Resource newResource = null;
66 for (Resource r : resources) {
67 String value = g.getPossibleRelatedValue(r, b.HasName);
68 if (null != value && value.equals(newInstanceName)) {
73 if (newResource == null) {
74 throw new ValidationException("Could not find created resource");
76 if (!g.isInstanceOf(newResource, b.Type))
77 throw new ValidationException("Created resource is not an instance of Type");
81 LifecycleSupport ls = session.getService(LifecycleSupport.class);
83 // } catch (ClassNotFoundException e) {
84 // throw new DatabaseException("Test failed.", e);