Skip to main content
summaryrefslogtreecommitdiffstats
blob: bc25ff4ad9729e567740db632218d02f72b58a8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*****************************************************************************
 * Copyright (c) 2010 CEA LIST.
 *    
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.core.queries.test.modisco;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.facet.infra.query.ModelQuery;
import org.eclipse.emf.facet.infra.query.runtime.ModelQueryParameterValue;
import org.eclipse.papyrus.infra.queries.core.modisco.QueryUtil;
import org.junit.BeforeClass;
import org.junit.Test;


/**
 * Tests cases for {@link BooleanTest_NoParameters}
 */
public class BooleanTest_NoParametersTests extends AbstractQueryUtilTest {

	/** query on which tests are based */
	protected static ModelQuery booleanQuery;

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		booleanQuery = QueryUtil.retrieveModelQuery(Messages.QueryUtilTest_TestName_BooleanTest_NoParameters, Messages.QueryUtilTest_QuerySetName_CoreQueriesTest);
		assertNotNull("Query " + Messages.QueryUtilTest_TestName_BooleanTest_NoParameters + " was not found.", booleanQuery);
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.core.queries.modisco.QueryUtil#retrieveModelQuery(java.lang.String, java.lang.String)}.
	 */
	@Test
	public final void testRetrieveModelQuery_BooleanTest_NoParameters() {
		assertNotNull("Query " + Messages.QueryUtilTest_TestName_BooleanTest_NoParameters + " was not found.", booleanQuery);
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.core.queries.modisco.QueryUtil#isValidQuery(org.eclipse.emf.facet.infra.query.ModelQuery)}.
	 */
	@Test
	public final void testIsValidQuery_BooleanTest_NoParameters() {
		IStatus status = QueryUtil.isValidQuery(booleanQuery);
		assertTrue("Query " + Messages.QueryUtilTest_TestName_BooleanTest_NoParameters + " should be a valid query. Current Status: " + status.getMessage(), status.isOK());
	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.core.queries.modisco.QueryUtil#evaluateBooleanQuery(org.eclipse.emf.facet.infra.query.ModelQuery, org.eclipse.emf.ecore.EObject, java.util.List)}
	 * .
	 */
	@Test
	public final void testEvaluateBooleanQueryBooleanTest_NoParameters() {
		boolean exceptionThrown;
		boolean result;

		// test with null as parameter
		exceptionThrown = false;
		result = false;
		try {
			result = QueryUtil.evaluateBooleanQuery(booleanQuery, umlPackage, new ArrayList<ModelQueryParameterValue>());
		} catch (Exception e) {
			exceptionThrown = true;
		}
		assertTrue(result);
		assertFalse("No Exception should be thrown", exceptionThrown);

		// test with an empty array list
		exceptionThrown = false;
		result = false;
		try {
			result = QueryUtil.evaluateBooleanQuery(booleanQuery, umlPackage, new ArrayList<ModelQueryParameterValue>());
		} catch (Exception e) {
			exceptionThrown = true;
		}
		assertTrue(result);
		assertFalse("No Exception should be thrown", exceptionThrown);

		// test with not an element context
		exceptionThrown = false;
		result = false;
		try {
			result = QueryUtil.evaluateBooleanQuery(booleanQuery, ecorePackage, new ArrayList<ModelQueryParameterValue>());
		} catch (Exception e) {
			exceptionThrown = true;
		}
		assertFalse("The query should not be valid, as the element is not a UML Element", result);
		// assertTrue("An exception should be thrown", exceptionThrown);
	}

}

Back to the top