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.api.write.claimValue;
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.request.Read;
24 import org.simantics.db.service.LifecycleSupport;
25 import org.simantics.db.testing.base.SimpleBase;
26 import org.simantics.db.testing.common.TestBase;
27 import org.simantics.db.testing.common.Tests;
28 import org.simantics.layer0.Layer0;
29 public class SetValueTest2 extends SimpleBase {
30 private static int NV = 258;
31 private static int VS = (1<<14)-1;
32 private final String value = "SetValue2" + getRandomString();
33 private final byte[] data;
34 public SetValueTest2() {
36 for (int i = 0; i < data.length; i++) {
41 public void testSetValue2() throws DatabaseException {
42 final Session s = getSession();
45 final Session s2 = Tests.getTestHandler().getSession();
49 LifecycleSupport ls = s2.getService(LifecycleSupport.class);
53 private void setValues(Session s) throws DatabaseException {
54 s.syncRequest(new WriteRequest() {
56 public void perform(WriteGraph g) throws DatabaseException {
57 Layer0 b = Layer0.getInstance(g);
58 Resource r = g.newResource();
59 g.claim(r, b.InstanceOf, null, b.Library);
60 g.claimLiteral(r, b.HasName, value);
61 g.claim(rl, b.ConsistsOf, r);
63 for (int i=0; i<NV; ++i) {
64 Resource rv = g.newResource();
65 g.claim(rv, b.InstanceOf, b.ByteArray);
66 g.claimValue(rv, data);
67 g.claim(r, b.HasProperty, rv);
72 private void checkValues(Session s) throws DatabaseException {
73 s.syncRequest(new Read<Resource>() {
75 public Resource perform(ReadGraph g) throws DatabaseException {
76 Layer0 l0 = Layer0.getInstance(g);
77 String uri = TestBase.ROOT_LIBRARY_URI + "/" + value;
78 Resource r = g.getResource(uri);
79 assertTrue(null != r);
80 Collection<Resource> resources = g.getObjects(r, l0.HasProperty);
82 for (Resource rv : resources) {
83 if (g.isInstanceOf(rv, l0.ByteArray)) {
84 byte[] data = g.getValue(rv);
85 if (data.length != VS)
86 fail("Value lenght does not match.");
87 for (int i = 0; i < data.length; i++) {
88 if (data[i] != (byte)i)
89 fail("Value content does not match.");
95 fail("Value count does not match. count=" + count);