1 /*******************************************************************************
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
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.graph.tests;
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;
27 public class TestResourceUtil2 {
30 public @Test void test() throws Exception {
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() {
41 public long adapt(long in) {
45 util.adaptValue( variant.getBinding(), variant.getValue(), la );
47 } catch (DataTypeSyntaxError e) {
49 } catch (BindingException e) {
51 } catch (RuntimeSerializerConstructionException e) {
53 } catch (AccessorException e) {