X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Ftests%2Forg%2Fsimantics%2Fgraph%2Ftests%2FTestResourceUtil2.java;h=f342f827f0c4593c1a6f66f2e486fe9b87ef0a2b;hb=7a7f73011a6364cbb80ce4ef04424472d345a65a;hp=83fda3a61aa1509e6f956c874e4b9ce2b6c12df0;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/TestResourceUtil2.java b/bundles/org.simantics.graph/tests/org/simantics/graph/tests/TestResourceUtil2.java index 83fda3a61..f342f827f 100644 --- a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/TestResourceUtil2.java +++ b/bundles/org.simantics.graph/tests/org/simantics/graph/tests/TestResourceUtil2.java @@ -1,59 +1,59 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.graph.tests; - -import org.junit.Test; -import org.simantics.databoard.Bindings; -import org.simantics.databoard.Datatypes; -import org.simantics.databoard.accessor.error.AccessorException; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.error.BindingException; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.databoard.parser.repository.DataTypeSyntaxError; -import org.simantics.databoard.serialization.RuntimeSerializerConstructionException; -import org.simantics.databoard.type.Datatype; -import org.simantics.graph.utils.TGResourceUtil; -import org.simantics.graph.utils.TGResourceUtil.LongAdapter; - -public class TestResourceUtil2 { - - - public @Test void test() throws Exception { - - try { - - 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 = {}}}]}"); - Binding b = Bindings.getBinding(dt); - Object value = b.createDefault(); - Variant variant = new Variant(b, value); - TGResourceUtil util = new TGResourceUtil(); - LongAdapter la = new LongAdapter() { - @Override - public long adapt(long in) { - return in; - } - }; - util.adaptValue( variant.getBinding(), variant.getValue(), la ); - - } catch (DataTypeSyntaxError e) { - e.printStackTrace(); - } catch (BindingException e) { - e.printStackTrace(); - } catch (RuntimeSerializerConstructionException e) { - e.printStackTrace(); - } catch (AccessorException e) { - e.printStackTrace(); - } - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.graph.tests; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Datatypes; +import org.simantics.databoard.accessor.error.AccessorException; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.error.BindingException; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.databoard.parser.repository.DataTypeSyntaxError; +import org.simantics.databoard.serialization.RuntimeSerializerConstructionException; +import org.simantics.databoard.type.Datatype; +import org.simantics.graph.utils.TGResourceUtil; +import org.simantics.graph.utils.TGResourceUtil.LongAdapter; + +public class TestResourceUtil2 { + + + public @Test void test() throws Exception { + + try { + + 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 = {}}}]}"); + Binding b = Bindings.getBinding(dt); + Object value = b.createDefault(); + Variant variant = new Variant(b, value); + TGResourceUtil util = new TGResourceUtil(); + LongAdapter la = new LongAdapter() { + @Override + public long adapt(long in) { + return in; + } + }; + util.adaptValue( variant.getBinding(), variant.getValue(), la ); + + } catch (DataTypeSyntaxError e) { + e.printStackTrace(); + } catch (BindingException e) { + e.printStackTrace(); + } catch (RuntimeSerializerConstructionException e) { + e.printStackTrace(); + } catch (AccessorException e) { + e.printStackTrace(); + } + + } + +}