1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 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 java.util.ArrayList;
15 import java.util.List;
17 import org.junit.Test;
18 import org.simantics.databoard.Bindings;
19 import org.simantics.databoard.annotations.Union;
20 import org.simantics.databoard.binding.Binding;
21 import org.simantics.databoard.binding.RecordBinding;
22 import org.simantics.graph.tests._RVI._RVIPart;
23 import org.simantics.graph.tests._RVI._ResourceRVIPart;
24 import org.simantics.graph.tests._RVI._Role;
25 import org.simantics.graph.tests._RVI._StringRVIPart;
26 import org.simantics.graph.utils.TGResourceUtil;
28 public class TestTGResourceUtil {
31 public @Test void test() throws Exception {
33 _ResourceRVIPart part1 = new _ResourceRVIPart();
35 part1.role = _Role.CHILD;
37 _StringRVIPart part2 = new _StringRVIPart();
38 part2.string = "Value";
39 part2.role = _Role.PROPERTY;
41 _RVI rvi = new _RVI();
42 rvi.parts = new _RVIPart[] { part1, part2 };
45 Binding b1 = Bindings.getBinding( _RVI.class );
46 RecordBinding b2 = Bindings.getBinding( _ResourceRVIPart.class );
47 b2.componentBindings[1].type().metadata.put("resource", "true");
49 TGResourceUtil util = new TGResourceUtil();
50 util.addType( b1.type() );
52 List<Long> resources = new ArrayList<Long>();
53 util.findResources(b1, rvi, resources);
54 for (Long l : resources) System.out.println("Found resource: "+l);
57 TGResourceUtil.LongAdapter la = new TGResourceUtil.LongAdapter() {
59 public long adapt(long in) {
63 util.adaptValue(b1, rvi, la);
65 System.out.println("rvi = "+b1.toString(rvi));
74 static enum _Role { CHILD, PROPERTY }
75 public _RVIPart[] parts;
76 @Union({_ResourceRVIPart.class, _StringRVIPart.class})
78 static class _ResourceRVIPart implements _RVIPart {
82 static class _StringRVIPart implements _RVIPart {
86 public Object variant;