Skip to main content
summaryrefslogtreecommitdiffstats
blob: b242d26dc93e2b8eb99b139066ccdb7573fc9485 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*****************************************************************************
 * 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.Arrays;
import java.util.HashMap;
import java.util.List;

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


/**
 * Test Class for {@link QueryUtil#isValidParameterSet(org.eclipse.emf.facet.infra.query.ModelQuery, java.util.Map)}
 */
public class QueryUtil_Parameters extends AbstractQueryUtilTest {

	/** queries on which tests are based */
	protected static ModelQuery queryBooleanTest_String_1, queryBooleanTest_Boolean_1_Integer_1, queryBooleanTest_Enum_1, queryBooleanTest_String_3, queryBooleanTest_String_Star;

	// list of possible values to test
	/** value: String */
	protected static String paramStringValue = "string";

	/** value: Integer */
	protected static int paramIntValue = 1;

	/** value: boolean */
	protected static boolean paramBooleanValue = true;

	/** value: Enumeration */
	protected static VisibilityKind paramEnumValue = VisibilityKind.PUBLIC_LITERAL;

	/** list of Strings */
	protected static List<String> paramStringList2Value = Arrays.asList("string1", "String2");

	/** list of Strings */
	protected static List<String> paramStringList4Value = Arrays.asList("string1", "String2", "string3", "String4");

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

		queryBooleanTest_Boolean_1_Integer_1 = QueryUtil.retrieveModelQuery(BooleanTest_Boolean_1_Integer_1, Messages.QueryUtilTest_QuerySetName_CoreQueriesTest);
		assertNotNull("Query " + BooleanTest_Boolean_1_Integer_1 + " was not found.", queryBooleanTest_Boolean_1_Integer_1);

		queryBooleanTest_Enum_1 = QueryUtil.retrieveModelQuery(BooleanTest_Enum_1, Messages.QueryUtilTest_QuerySetName_CoreQueriesTest);
		assertNotNull("Query " + BooleanTest_Enum_1 + " was not found.", queryBooleanTest_Enum_1);

		queryBooleanTest_String_3 = QueryUtil.retrieveModelQuery(BooleanTest_String_3, Messages.QueryUtilTest_QuerySetName_CoreQueriesTest);
		assertNotNull("Query " + BooleanTest_String_3 + " was not found.", queryBooleanTest_String_3);

		queryBooleanTest_String_Star = QueryUtil.retrieveModelQuery(BooleanTest_String_Star, Messages.QueryUtilTest_QuerySetName_CoreQueriesTest);
		assertNotNull("Query " + BooleanTest_String_Star + " was not found.", queryBooleanTest_String_Star);
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.core.queries.modisco.QueryUtil#isValidParameterSet(org.eclipse.emf.facet.infra.query.ModelQuery, java.util.Map)}.
	 */
	@Test
	public final void testIsValidParameterSet_String_Valid() {
		// public static final IStatus isValidParameterSet(ModelQuery query, Map<String, Object> parameters);
		HashMap<String, Object> validParamSet = new HashMap<String, Object>();
		validParamSet.put(BooleanTest_String_1_StringParamName, paramStringValue);
		IStatus status = QueryUtil.isValidParameterSet(queryBooleanTest_String_1, validParamSet);

		assertTrue("Status should be OK: " + status, status.isOK());
	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.core.queries.modisco.QueryUtil#isValidParameterSet(org.eclipse.emf.facet.infra.query.ModelQuery, java.util.Map)}.
	 */
	@Test
	public final void testIsValidParameterSet_String_WrongName() {
		// public static final IStatus isValidParameterSet(ModelQuery query, Map<String, Object> parameters);
		HashMap<String, Object> validParamSet = new HashMap<String, Object>();
		validParamSet.put(BooleanTest_String_1_StringParamName + "NotValid", paramStringValue);
		IStatus status = QueryUtil.isValidParameterSet(queryBooleanTest_String_1, validParamSet);

		assertTrue("Status should be ERROR: " + status, status.getSeverity() == IStatus.ERROR);
	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.core.queries.modisco.QueryUtil#isValidParameterSet(org.eclipse.emf.facet.infra.query.ModelQuery, java.util.Map)}.
	 */
	@Test
	public final void testIsValidParameterSet_String_WrongSize() {
		// public static final IStatus isValidParameterSet(ModelQuery query, Map<String, Object> parameters);
		HashMap<String, Object> validParamSet = new HashMap<String, Object>();
		validParamSet.put(BooleanTest_String_1_StringParamName, paramStringValue);
		validParamSet.put(BooleanTest_String_1_StringParamName + "NotValid", paramStringValue);
		IStatus status = QueryUtil.isValidParameterSet(queryBooleanTest_String_1, validParamSet);

		assertTrue("Status should be ERROR: " + status, status.getSeverity() == IStatus.ERROR);
	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.core.queries.modisco.QueryUtil#isValidParameterSet(org.eclipse.emf.facet.infra.query.ModelQuery, java.util.Map)}.
	 */
	@Test
	public final void testIsValidParameterSet_String_WrongType() {
		// public static final IStatus isValidParameterSet(ModelQuery query, Map<String, Object> parameters);
		HashMap<String, Object> validParamSet = new HashMap<String, Object>();
		validParamSet.put(BooleanTest_String_1_StringParamName, paramBooleanValue);
		IStatus status = QueryUtil.isValidParameterSet(queryBooleanTest_String_1, validParamSet);
		System.err.println("warning, no test is currently run for type: " + status);
		// FIXME: warning, no test is currently run for type 
		// assertTrue("Status should be ERROR: " + status, status.getSeverity() == IStatus.ERROR);
	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.core.queries.modisco.QueryUtil#isValidParameterSet(org.eclipse.emf.facet.infra.query.ModelQuery, java.util.Map)}.
	 */
	@Test
	public final void testIsValidParameterSet_BooleanInteger_WrongSize() {
		// public static final IStatus isValidParameterSet(ModelQuery query, Map<String, Object> parameters);
		HashMap<String, Object> validParamSet = new HashMap<String, Object>();
		validParamSet.put(BooleanTest_String_1_StringParamName, paramStringValue);
		IStatus status = QueryUtil.isValidParameterSet(queryBooleanTest_Boolean_1_Integer_1, validParamSet);

		assertTrue("Status should be ERROR: " + status, status.getSeverity() == IStatus.ERROR);
	}

	/**
	 * 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.Map)}
	 * .
	 */
	@Test
	public final void testEvaluateBooleanQuery_BooleanTest_String_1_Valid() {
		// public static final IStatus isValidParameterSet(ModelQuery query, Map<String, Object> parameters);
		HashMap<String, Object> validParamSet = new HashMap<String, Object>();
		validParamSet.put(BooleanTest_String_1_StringParamName, paramStringValue);
		boolean exceptionThrown = false;
		boolean result = false;
		try {
			result = QueryUtil.evaluateBooleanQuery(queryBooleanTest_String_1, umlPackage, validParamSet);
		} catch (Exception e) {
			exceptionThrown = true;
		}
		assertTrue("result should be valid.", result);
		assertFalse("No Exception should be thrown", exceptionThrown);
	}

	/**
	 * 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.Map)}
	 * .
	 */
	@Test
	public final void testEvaluateBooleanQuery_BooleanTest_String_1_NotValid() {
		// public static final IStatus isValidParameterSet(ModelQuery query, Map<String, Object> parameters);
		HashMap<String, Object> validParamSet = new HashMap<String, Object>();
		validParamSet.put(BooleanTest_String_1_StringParamName, paramBooleanValue);
		@SuppressWarnings("unused")
		boolean exceptionThrown = false;
		boolean result = false;
		try {
			result = QueryUtil.evaluateBooleanQuery(queryBooleanTest_String_1, umlPackage, validParamSet);
		} catch (Exception e) {
			exceptionThrown = true;
		}
		assertFalse("result should not be valid, as the value given is a boolean", result);
		// assertTrue("An exception should be thrown", exceptionThrown);
	}

}

Back to the top