]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest7.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / misc / SyncAsyncSyncTest7.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.db.tests.api.request.misc;
13
14 import org.junit.Test;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.Session;
18 import org.simantics.db.adaption.AdaptionService;
19 import org.simantics.db.common.adaption.SimpleAdapter;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.exception.ServiceException;
22 import org.simantics.db.exception.ValidationException;
23 import org.simantics.db.request.Read;
24 import org.simantics.db.services.adaption.AdaptionService2;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26 import org.simantics.layer0.Layer0;
27
28 public class SyncAsyncSyncTest7 extends ExistingDatabaseTest {
29         
30         @Test
31     public void test() throws Exception {
32                 
33                 Session session = getSession();
34
35                 AdaptionService2 adaptionService = new AdaptionService2();
36                 Layer0 b = Layer0.getInstance(session);
37                 adaptionService.addAdapter(b.Entity, String.class, new SimpleAdapter<String>() {
38
39             @Override
40             public String adapt(ReadGraph g, Resource r) throws ValidationException, ServiceException {
41                 return "SIMPLE";
42             }
43             
44         });
45                 
46                 session.registerService(AdaptionService.class, adaptionService);
47                 
48         session.syncRequest(new Read<String>() {
49
50             @Override
51             public String perform(ReadGraph graph) throws DatabaseException {
52                 
53 //                Assert.isTrue(path.length > 0);
54 //                String[] namePath = new String[path.length];
55 //                String description = "";
56 //                int version = 0;
57 //                for (int i = 0; i < namePath.length; i++) {
58 //                    String name = g.getRelatedValue(path[i], g.getBuiltins().HasName);
59 //                    Assert.isTrue(name != null);
60 //                    Assert.isTrue(name.length() > 0);
61 //                    namePath[i] = name;
62 //
63 //                    Layer0 b = Layer0.getInstance(g);
64 //
65 //                    if (i == namePath.length - 1) {
66 //                        if (g.isInstanceOf(path[i], b.Project2)) {
67 //                            version = 2;
68 //                            StringBuilder desc = new StringBuilder();
69 //                            boolean first = true;
70 //                            for (Resource pf : g.getObjects(path[i], b.HasFeature)) {
71 //                                if (!first) {
72 //                                    desc.append(", ");
73 //                                }
74 //                                first = false;
75 //                                String d = null;
76 //                                try {
77                                     return graph.adapt(graph.getRootLibrary(), String.class);
78 //                                } catch (AdaptionException e) {
79 //                                    d = GraphUtils.getReadableName(g, pf.get());
80 //                                }
81 //                                desc.append(d);
82 //                            }
83 //                            description = desc.toString();
84 //                        }
85 //                    }
86                 
87             }
88             
89         });
90         
91         }
92
93 }