1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.graph.tester;
\r
14 import org.simantics.Simantics;
\r
15 import org.simantics.browsing.ui.Tester;
\r
16 import org.simantics.browsing.ui.common.Testers;
\r
17 import org.simantics.db.RequestProcessor;
\r
18 import org.simantics.db.Resource;
\r
19 import org.simantics.db.Session;
\r
20 import org.simantics.db.exception.DatabaseException;
\r
21 import org.simantics.layer0.Layer0;
\r
22 import org.simantics.simulation.ontology.SimulationResource;
\r
25 * A facade class for constructing new {@link Tester} instances for standard
\r
26 * graph based testing activities. Please use this class instead of directly
\r
27 * referring to <code>org.simantics.browsing.ui.graph.tester</code> package
\r
30 * @author Tuukka Lehtonen
\r
32 public final class GraphTesters {
\r
34 public static Tester pass() {
\r
35 return Testers.PASS;
\r
38 public static Tester fail() {
\r
39 return Testers.FAIL;
\r
46 * TODO: throw exceptions, don't catch.
\r
48 public static Tester type(final String uri) {
\r
50 return type(Simantics.getSession(), uri);
\r
51 } catch (DatabaseException e) {
\r
52 e.printStackTrace();
\r
57 public static Tester standardContextType(final String uri) {
\r
59 return standardContextType(Simantics.getSession(), uri);
\r
60 } catch (DatabaseException e) {
\r
61 e.printStackTrace();
\r
66 public static Tester standardContextType(Session s, final String uri) throws DatabaseException {
\r
67 return new StandardContextHasSomeTypeTester(s, uri);
\r
70 public static Tester type(Session s, final String uri) throws DatabaseException {
\r
71 return new HasSomeTypeTester(s, uri);
\r
74 public static Tester type(Resource resource) {
\r
75 return new HasSomeTypeTester(resource);
\r
82 * TODO: throw exceptions, don't catch.
\r
84 public static Tester resource(final String uri) {
\r
86 return resource(Simantics.getSession(), uri);
\r
87 } catch (DatabaseException e) {
\r
88 e.printStackTrace();
\r
93 public static Tester resource(Session s, final String uri) throws DatabaseException {
\r
94 return new EqualsResourceTester(s, uri);
\r
97 public static Tester resource(Resource resource) {
\r
98 return new EqualsResourceTester(resource);
\r
101 public static Tester inherits(Resource resource) {
\r
102 return new InheritsSomeTypeTester(resource);
\r
105 public static Tester model() throws DatabaseException {
\r
106 Session s = Simantics.getSession();
\r
107 SimulationResource SIMU = SimulationResource.getInstance(s);
\r
108 return new HasSomeTypeTester(SIMU.Model);
\r
111 public static Tester type() {
\r
112 return new HasSomeTypeTester(Simantics.getSession().getService(Layer0.class).Type);
\r
115 public static Tester orderedSet() {
\r
116 return new OrderedSetTester(Simantics.getSession());
\r
119 public static Tester orderedSet(Session s) {
\r
120 return new OrderedSetTester(s);
\r
123 public static Tester hasRelatedObjects(Resource relation) {
\r
124 return new HasRelatedObjectsTester(relation);
\r
127 public static Tester hasRelatedObjects(RequestProcessor processor, String relationUri) throws DatabaseException {
\r
128 return new HasRelatedObjectsTester(processor, relationUri);
\r
131 public static Tester hasRelatedObjects(String relationUri) {
\r
133 return hasRelatedObjects(Simantics.getSession(), relationUri);
\r
134 } catch (DatabaseException e) {
\r
135 e.printStackTrace();
\r