1 package org.simantics.db.tests.regression.bugs;
3 /*******************************************************************************
4 * Copyright (c) 2014 Association for Decentralized Information Management
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
12 * VTT Technical Research Centre of Finland - initial API and implementation
13 *******************************************************************************/
15 import org.junit.Test;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.Resource;
18 import org.simantics.db.Session;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.common.request.WriteRequest;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.service.ServerInformation;
23 import org.simantics.db.testing.base.ExistingDatabaseTest;
24 import org.simantics.db.testing.common.TestBase;
27 * Tests that database identifier stays the same during purge.
28 * The tests requires that it is called at least twice and purge is done between the calls.
30 public class Issue5432Test1 extends ExistingDatabaseTest {
31 private final String URI_NAME = "DatabaseId";
32 private final String URI_PATH = TestBase.ROOT_LIBRARY_URI + "/" + URI_NAME;
34 public void test() throws DatabaseException {
35 Session session = getSession();
36 session.syncRequest(new Init());
38 class Init extends WriteRequest {
40 public void perform(WriteGraph g) throws DatabaseException {
41 Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI);
42 Resource testRoot = g.getPossibleResource(URI_PATH);
43 ServerInformation si = g.getService(ServerInformation.class);
44 String id = si.getDatabaseId();
45 if (null == testRoot) {
46 testRoot = g.newResource();
47 g.claim(testRoot, L0.InstanceOf, L0.Library);
48 g.addLiteral(testRoot, L0.HasName, L0.NameOf, L0.String, URI_NAME, Bindings.STRING);
49 g.addLiteral(testRoot, L0.DatabaseManagement_HasVersionedId, null, L0.String, id, Bindings.STRING);
50 g.claim(rl, L0.ConsistsOf, testRoot);
52 String databaseId = g.getRelatedValue(testRoot, L0.DatabaseManagement_HasVersionedId);
53 assertTrue(databaseId.equals(id));