]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph/tests/org/simantics/graph/tests/TestResourceUtil2.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graph / tests / org / simantics / graph / tests / TestResourceUtil2.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
3  * 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.graph.tests;
13
14 import org.junit.Test;
15 import org.simantics.databoard.Bindings;
16 import org.simantics.databoard.Datatypes;
17 import org.simantics.databoard.accessor.error.AccessorException;
18 import org.simantics.databoard.binding.Binding;
19 import org.simantics.databoard.binding.error.BindingException;
20 import org.simantics.databoard.binding.mutable.Variant;
21 import org.simantics.databoard.parser.repository.DataTypeSyntaxError;
22 import org.simantics.databoard.serialization.RuntimeSerializerConstructionException;
23 import org.simantics.databoard.type.Datatype;
24 import org.simantics.graph.utils.TGResourceUtil;
25 import org.simantics.graph.utils.TGResourceUtil.LongAdapter;
26
27 public class TestResourceUtil2 {
28
29         
30         public @Test void test() throws Exception {
31         
32             try {
33         
34                 Datatype dt = Datatypes.translate("RecordType {metadata = {}, components = [{name = \"configuration\", type = UnionType {metadata = {}, components = [{name = \"AprosComposite\", type = RecordType {metadata = {}, components = [{name = \"resourceId\", type = LongType {metadata = {}}}, {name = \"childMap\", type = MapType {metadata = {}, keyType = StringType {metadata = {}}, valueType = UnionType a}}, {name = \"sourceTypeUri\", type = OptionalType {metadata = {}, componentType = StringType {metadata = {}}}}]}}, {name = \"AprosComponent\", type = RecordType {metadata = {}, components = [{name = \"resourceId\", type = LongType {metadata = {}}}, {name = \"moduleId\", type = IntegerType {metadata = {}}}, {name = \"parametrized\", type = BooleanType {metadata = {}}}]}}]}/a}, {name = \"currentRevision\", type = LongType {metadata = {}}}]}");
35                 Binding b = Bindings.getBinding(dt);
36                 Object value = b.createDefault();
37                 Variant variant = new Variant(b, value);
38                 TGResourceUtil util = new TGResourceUtil();
39                 LongAdapter la = new LongAdapter() {
40                     @Override
41                     public long adapt(long in) {
42                         return in;
43                     }            
44                 };
45                 util.adaptValue( variant.getBinding(), variant.getValue(), la );                        
46         
47             } catch (DataTypeSyntaxError e) {
48                 e.printStackTrace();
49             } catch (BindingException e) {
50                 e.printStackTrace();
51             } catch (RuntimeSerializerConstructionException e) {
52                 e.printStackTrace();
53             } catch (AccessorException e) {
54                 e.printStackTrace();
55             }
56     
57         }
58         
59 }