]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph/tests/org/simantics/graph/tests/TestTGResourceUtil.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graph / tests / org / simantics / graph / tests / TestTGResourceUtil.java
diff --git a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/TestTGResourceUtil.java b/bundles/org.simantics.graph/tests/org/simantics/graph/tests/TestTGResourceUtil.java
new file mode 100644 (file)
index 0000000..9bb53d3
--- /dev/null
@@ -0,0 +1,88 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.graph.tests;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.junit.Test;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.annotations.Union;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.binding.RecordBinding;\r
+import org.simantics.graph.tests._RVI._RVIPart;\r
+import org.simantics.graph.tests._RVI._ResourceRVIPart;\r
+import org.simantics.graph.tests._RVI._Role;\r
+import org.simantics.graph.tests._RVI._StringRVIPart;\r
+import org.simantics.graph.utils.TGResourceUtil;\r
+\r
+public class TestTGResourceUtil {\r
+       \r
+       \r
+       public @Test void test() throws Exception {\r
+               \r
+               _ResourceRVIPart part1 = new _ResourceRVIPart();\r
+               part1.resource = 5;\r
+               part1.role = _Role.CHILD;\r
+               \r
+               _StringRVIPart part2 = new _StringRVIPart();\r
+               part2.string = "Value";\r
+               part2.role = _Role.PROPERTY;\r
+               \r
+               _RVI rvi = new _RVI();\r
+               rvi.parts = new _RVIPart[] { part1, part2 };\r
+               rvi.variant = 3L;\r
+               \r
+               Binding b1 = Bindings.getBinding( _RVI.class );\r
+               RecordBinding b2 = Bindings.getBinding( _ResourceRVIPart.class );\r
+               b2.componentBindings[1].type().metadata.put("resource", "true");\r
+               \r
+               TGResourceUtil util = new TGResourceUtil();\r
+               util.addType( b1.type() );\r
+               \r
+               List<Long> resources = new ArrayList<Long>();\r
+               util.findResources(b1, rvi, resources);\r
+               for (Long l : resources) System.out.println("Found resource: "+l);\r
+               \r
+               // adapt resources\r
+               TGResourceUtil.LongAdapter la = new TGResourceUtil.LongAdapter() {\r
+                       @Override\r
+                       public long adapt(long in) {\r
+                               return in;\r
+                       }\r
+               };\r
+               util.adaptValue(b1, rvi, la);\r
+               \r
+               System.out.println("rvi = "+b1.toString(rvi));          \r
+       }\r
+       \r
+       \r
+\r
+}\r
+\r
+class _RVI {\r
+       \r
+       static enum _Role { CHILD, PROPERTY }   \r
+       public _RVIPart[] parts;\r
+       @Union({_ResourceRVIPart.class, _StringRVIPart.class})\r
+       interface _RVIPart {}\r
+       static class _ResourceRVIPart implements _RVIPart {\r
+               public _Role role;\r
+               public long resource;\r
+       }\r
+       static class _StringRVIPart implements _RVIPart {\r
+               public _Role role;\r
+               public String string;\r
+       }       \r
+       public Object variant;\r
+\r
+}
\ No newline at end of file