/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.db.tests.api.write.claimValue; import java.util.Collection; import org.junit.Test; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.request.Read; import org.simantics.db.service.LifecycleSupport; import org.simantics.db.testing.base.SimpleBase; import org.simantics.db.testing.common.TestBase; import org.simantics.db.testing.common.Tests; import org.simantics.layer0.Layer0; public class SetValueTest2 extends SimpleBase { private static int NV = 258; private static int VS = (1<<14)-1; private final String value = "SetValue2" + getRandomString(); private final byte[] data; public SetValueTest2() { data = new byte[VS]; for (int i = 0; i < data.length; i++) { data[i] = (byte)(i); } } @Test public void testSetValue2() throws DatabaseException { final Session s = getSession(); setValues(s); checkValues(s); final Session s2 = Tests.getTestHandler().getSession(); try { checkValues(s2); } finally { LifecycleSupport ls = s2.getService(LifecycleSupport.class); ls.close(); } } private void setValues(Session s) throws DatabaseException { s.syncRequest(new WriteRequest() { @Override public void perform(WriteGraph g) throws DatabaseException { Layer0 b = Layer0.getInstance(g); Resource r = g.newResource(); g.claim(r, b.InstanceOf, null, b.Library); g.claimLiteral(r, b.HasName, value); g.claim(rl, b.ConsistsOf, r); g.flushCluster(); for (int i=0; i() { @Override public Resource perform(ReadGraph g) throws DatabaseException { Layer0 l0 = Layer0.getInstance(g); String uri = TestBase.ROOT_LIBRARY_URI + "/" + value; Resource r = g.getResource(uri); assertTrue(null != r); Collection resources = g.getObjects(r, l0.HasProperty); int count = 0; for (Resource rv : resources) { if (g.isInstanceOf(rv, l0.ByteArray)) { byte[] data = g.getValue(rv); if (data.length != VS) fail("Value lenght does not match."); for (int i = 0; i < data.length; i++) { if (data[i] != (byte)i) fail("Value content does not match."); } ++count; } } if (count != NV) fail("Value count does not match. count=" + count); return null; } }); } }