1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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.db.tests.api.request.misc;
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;
28 public class SyncAsyncSyncTest7 extends ExistingDatabaseTest {
31 public void test() throws Exception {
33 Session session = getSession();
35 AdaptionService2 adaptionService = new AdaptionService2();
36 Layer0 b = Layer0.getInstance(session);
37 adaptionService.addAdapter(b.Entity, String.class, new SimpleAdapter<String>() {
40 public String adapt(ReadGraph g, Resource r) throws ValidationException, ServiceException {
46 session.registerService(AdaptionService.class, adaptionService);
48 session.syncRequest(new Read<String>() {
51 public String perform(ReadGraph graph) throws DatabaseException {
53 // Assert.isTrue(path.length > 0);
54 // String[] namePath = new String[path.length];
55 // String description = "";
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;
63 // Layer0 b = Layer0.getInstance(g);
65 // if (i == namePath.length - 1) {
66 // if (g.isInstanceOf(path[i], b.Project2)) {
68 // StringBuilder desc = new StringBuilder();
69 // boolean first = true;
70 // for (Resource pf : g.getObjects(path[i], b.HasFeature)) {
77 return graph.adapt(graph.getRootLibrary(), String.class);
78 // } catch (AdaptionException e) {
79 // d = GraphUtils.getReadableName(g, pf.get());
83 // description = desc.toString();