]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/adapt/AdaptTest4.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / readGraph / adapt / AdaptTest4.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.readGraph.adapt;
13
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.request.ResourceAsyncRead;
18 import org.simantics.db.exception.AdaptionException;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.procedure.AsyncProcedure;
21 import org.simantics.db.testing.base.WriteReadTest;
22 import org.simantics.db.tests.api.readGraph.common.Ontologies;
23
24 /**
25  * Checks that {@link ReadGraph#adapt(org.simantics.db.Resource, Class)},
26  * {@link ReadGraph#adaptUnique(org.simantics.db.Resource, Class)},
27  * <code>AsyncReadGraph.forAdapted</code> fail as expected.
28  * 
29  * <p>
30  * Regression test for https://www.simulationsite.net/trac/simantics/ticket/617
31  * 
32  * @author Tuukka Lehtonen
33  */
34 public class AdaptTest4 extends WriteReadTest {
35
36         @Override
37         protected void write(WriteGraph graph) throws DatabaseException {
38                 written = Ontologies.relatedTypelessResource(L0, graph);
39         }
40
41         @Override
42         protected void read(ReadGraph graph) throws DatabaseException {
43                 try {
44
45                         String s = graph
46                                         .syncRequest(new ResourceAsyncRead<String>(written) {
47                                                 @Override
48                                                 public void perform(AsyncReadGraph graph,
49                                                                 AsyncProcedure<String> procedure) {
50                                                         graph.forAdapted(resource, String.class, procedure);
51                                                 }
52                                         });
53                         assertTrue("adapt must never return null", s != null);
54                 } catch (AdaptionException e) {
55                         return;
56                 } catch (Exception e) {
57                         fail("Wrong exception: " + e.getClass().getCanonicalName());
58                 }
59                 fail("Should throw");
60         }
61 }