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.browsing.ui.graph.tester;
14 import org.simantics.Simantics;
15 import org.simantics.browsing.ui.Tester;
16 import org.simantics.browsing.ui.common.Testers;
17 import org.simantics.db.RequestProcessor;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Session;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.layer0.Layer0;
22 import org.simantics.simulation.ontology.SimulationResource;
25 * A facade class for constructing new {@link Tester} instances for standard
26 * graph based testing activities. Please use this class instead of directly
27 * referring to <code>org.simantics.browsing.ui.graph.tester</code> package
30 * @author Tuukka Lehtonen
32 public final class GraphTesters {
34 public static Tester pass() {
38 public static Tester fail() {
46 * TODO: throw exceptions, don't catch.
48 public static Tester type(final String uri) {
50 return type(Simantics.getSession(), uri);
51 } catch (DatabaseException e) {
57 public static Tester standardContextType(final String uri) {
59 return standardContextType(Simantics.getSession(), uri);
60 } catch (DatabaseException e) {
66 public static Tester standardContextType(Session s, final String uri) throws DatabaseException {
67 return new StandardContextHasSomeTypeTester(s, uri);
70 public static Tester type(Session s, final String uri) throws DatabaseException {
71 return new HasSomeTypeTester(s, uri);
74 public static Tester type(Resource resource) {
75 return new HasSomeTypeTester(resource);
82 * TODO: throw exceptions, don't catch.
84 public static Tester resource(final String uri) {
86 return resource(Simantics.getSession(), uri);
87 } catch (DatabaseException e) {
93 public static Tester resource(Session s, final String uri) throws DatabaseException {
94 return new EqualsResourceTester(s, uri);
97 public static Tester resource(Resource resource) {
98 return new EqualsResourceTester(resource);
101 public static Tester inherits(Resource resource) {
102 return new InheritsSomeTypeTester(resource);
105 public static Tester model() throws DatabaseException {
106 Session s = Simantics.getSession();
107 SimulationResource SIMU = SimulationResource.getInstance(s);
108 return new HasSomeTypeTester(SIMU.Model);
111 public static Tester type() {
112 return new HasSomeTypeTester(Simantics.getSession().getService(Layer0.class).Type);
115 public static Tester orderedSet() {
116 return new OrderedSetTester(Simantics.getSession());
119 public static Tester orderedSet(Session s) {
120 return new OrderedSetTester(s);
123 public static Tester hasRelatedObjects(Resource relation) {
124 return new HasRelatedObjectsTester(relation);
127 public static Tester hasRelatedObjects(RequestProcessor processor, String relationUri) throws DatabaseException {
128 return new HasRelatedObjectsTester(processor, relationUri);
131 public static Tester hasRelatedObjects(String relationUri) {
133 return hasRelatedObjects(Simantics.getSession(), relationUri);
134 } catch (DatabaseException e) {