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.support.transferableGraphSupport;
14 import java.io.IOException;
15 import java.util.UUID;
17 import org.junit.Test;
18 import org.simantics.databoard.Bindings;
19 import org.simantics.databoard.binding.Binding;
20 import org.simantics.databoard.serialization.SerializationException;
21 import org.simantics.databoard.serialization.Serializer;
22 import org.simantics.databoard.serialization.SerializerConstructionException;
23 import org.simantics.db.ReadGraph;
24 import org.simantics.db.Resource;
25 import org.simantics.db.Session;
26 import org.simantics.db.WriteGraph;
27 import org.simantics.db.common.request.ReadRequest;
28 import org.simantics.db.common.request.WriteRequest;
29 import org.simantics.db.exception.DatabaseException;
30 import org.simantics.db.service.TransferableGraphSupport;
31 import org.simantics.db.testing.base.ExistingDatabaseTest;
32 import org.simantics.layer0.Layer0;
33 import org.simantics.utils.DataContainer;
35 public class TransferableGraphSupportTest2 extends ExistingDatabaseTest {
38 public void test() throws Exception {
40 Session session = getSession();
42 final String value = UUID.randomUUID().toString();
43 final TransferableGraphSupport support = session.getService(TransferableGraphSupport.class);
44 final DataContainer<Resource> resource = new DataContainer<Resource>();
47 session.syncRequest(new WriteRequest() {
49 public void perform(WriteGraph graph) throws DatabaseException {
51 Layer0 b = Layer0.getInstance(graph);
53 Resource r = graph.newResource();
55 graph.claim(r, b.InstanceOf, null, b.String);
58 Binding binding = Bindings.STRING;
59 Serializer serializer = Bindings.getSerializer( binding );
60 byte[] raw = serializer.serialize(value);
61 support.setValue(graph, r, null, raw);
62 } catch (SerializerConstructionException e) {
64 } catch (SerializationException e) {
66 } catch (IOException e) {
71 } catch (Throwable e) {
73 fail("Write transaction threw an unknown exception " + e);
78 session.syncRequest(new ReadRequest() {
80 public void run(ReadGraph graph) throws DatabaseException {
81 String v = graph.getValue(resource.get());
82 assert(v.equals(value));
85 } catch (Throwable e) {
86 fail("Write transaction threw an unknown exception " + e);