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.Arrays;
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.common.request.ReadRequest;
27 import org.simantics.db.exception.DatabaseException;
28 import org.simantics.db.service.TransferableGraphSupport;
29 import org.simantics.db.testing.annotation.Fails;
30 import org.simantics.db.testing.base.ExistingDatabaseTest;
31 import org.simantics.layer0.Layer0;
33 public class TransferableGraphSupportTest1 extends ExistingDatabaseTest {
37 public void test() throws Exception {
39 Session session = getSession();
40 final TransferableGraphSupport support = session.getService(TransferableGraphSupport.class);
43 session.syncRequest(new ReadRequest() {
45 public void run(ReadGraph g) throws DatabaseException {
46 // Use any non-functional relation
47 Layer0 b = Layer0.getInstance(g);
48 Resource name = g.getSingleObject(g.getRootLibrary(), b.HasName);
49 Object value = g.getValue(name);
50 Binding binding = Bindings.STRING;
52 Serializer serializer = Bindings.getSerializer( binding );
53 byte[] data = serializer.serialize(value);
54 byte[] raw = support.getValue(g, name);
55 assert(Arrays.equals(data, raw));
56 } catch (SerializerConstructionException e) {
58 } catch (SerializationException e) {
60 } catch (IOException e) {
65 } catch (Throwable e) {
66 fail("Write transaction threw an unknown exception ", e);