]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/transferableGraphSupport/TransferableGraphSupportTest1.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / support / transferableGraphSupport / TransferableGraphSupportTest1.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.api.support.transferableGraphSupport;
13
14 import java.io.IOException;
15 import java.util.Arrays;
16
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;
32
33 public class TransferableGraphSupportTest1 extends ExistingDatabaseTest {
34
35     @Test
36     @Fails
37     public void test() throws Exception {
38
39         Session session = getSession();
40         final TransferableGraphSupport support = session.getService(TransferableGraphSupport.class);
41
42         try {
43             session.syncRequest(new ReadRequest() {
44                 @Override
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;
51                     try {
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) {
57                         throw new Error(e);
58                     } catch (SerializationException e) {
59                         throw new Error(e);
60                     } catch (IOException e) {
61                         throw new Error(e);
62                     }
63                 }
64             });
65         } catch (Throwable e) {
66             fail("Write transaction threw an unknown exception ", e);
67         }
68
69     }
70
71 }