Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2d1a33af89642c3fe057289eacd3c8f67c70d313 (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
/*****************************************************************************
 * Copyright (c) 2021 Christian W. Damus, CEA LIST, and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Christian W. Damus - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.toolsmiths.validation.architecture.tests;

import static org.eclipse.papyrus.junit.matchers.MoreMatchers.regexContains;
import static org.eclipse.papyrus.junit.matchers.WorkspaceMatchers.isMarkerMessage;
import static org.eclipse.papyrus.junit.matchers.WorkspaceMatchers.isMarkerSeverity;
import static org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants.ARCHITECTURE_PLUGIN_VALIDATION_MARKER_TYPE;
import static org.hamcrest.CoreMatchers.both;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.List;

import org.eclipse.core.resources.IMarker;
import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.AuxProject;
import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.Build;
import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.MarkerType;
import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.OverlayFile;
import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProject;
import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProjectFixture;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;

/**
 * Test cases for the <em>Architecture Domain Model</em> validation of the model resource
 * in the project builder.
 */
@RunWith(Enclosed.class)
public class ArchitectureModelBuilderTest extends AbstractPapyrusTest {

	@TestProject("org.eclipse.papyrus.toolsmiths.validation.architecture.example")
	@MarkerType(ARCHITECTURE_PLUGIN_VALIDATION_MARKER_TYPE)
	@Build
	public static class Intrinsic {
		/**
		 * The project fixture to manage easily the project.
		 */
		@Rule
		public final TestProjectFixture fixture = new TestProjectFixture();

		/**
		 * Test the reporting of an unresolved creation command class.
		 */
		@Test
		@OverlayFile(value = "bug570097-models/BookStore-missingCommandClass.architecture", path = "resources/BookStore.architecture")
		public void unresolvedCreationCommandClass() {
			final List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$

			assertThat(modelMarkers, hasItem(both(isMarkerSeverity(IMarker.SEVERITY_ERROR)).and(isMarkerMessage(
					regexContains("Model creation command .* not found in the Java classpath"))))); //$NON-NLS-1$
		}

		/**
		 * Test the reporting of a creation command class that exists but does not conform to {@code IModelCreationCommand}.
		 */
		@Test
		@OverlayFile(value = "bug570097-models/BookStore-invalidCommandClass.architecture", path = "resources/BookStore.architecture")
		public void invalidCreationCommandClass() {
			final List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$

			assertThat(modelMarkers, hasItem(both(isMarkerSeverity(IMarker.SEVERITY_ERROR)).and(isMarkerMessage(
					regexContains("Model conversion command .* the IModelConversionCommand interface"))))); //$NON-NLS-1$
		}

		/**
		 * Test that validation finds a creation command class that is a binary JDT type (from the target platform).
		 * Other test cases cover source types.
		 */
		@Test
		@OverlayFile(value = "bug570097-models/BookStore-commandClassBinaryType.architecture", path = "resources/BookStore.architecture")
		// Create another project that brings Papyrus UML Class Diagram onto the classpath so that our
		// command class reference is resolvable by JDT as a binary type
		@AuxProject("org.eclipse.papyrus.toolsmiths.validation.architecture.classdiagram")
		public void creationCommandClassBinaryTypeResolved() {
			final List<IMarker> modelMarkers = fixture.getMarkers("META-INF/MANIFEST.MF"); //$NON-NLS-1$

			assertThat(modelMarkers, not(hasItem(isMarkerMessage(containsString("creation command"))))); //$NON-NLS-1$
		}
	}

	@TestProject("org.eclipse.papyrus.toolsmiths.validation.architecture.example")
	@MarkerType(ARCHITECTURE_PLUGIN_VALIDATION_MARKER_TYPE)
	@Build
	public static class Custom {
		/**
		 * The project fixture to manage easily the project.
		 */
		@Rule
		public final TestProjectFixture fixture = new TestProjectFixture();

		/**
		 * Test the reporting of an icon that doesn't exist.
		 */
		@Test
		@OverlayFile(value = "bug570097-models/BookStore-missingIcon.architecture", path = "resources/BookStore.architecture")
		public void unresolvedIconResourceURI() {
			final List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$

			assertThat(modelMarkers, hasItem(both(isMarkerSeverity(IMarker.SEVERITY_ERROR)).and(isMarkerMessage(containsString("no-such-icon.png"))))); //$NON-NLS-1$
		}

		/**
		 * Test the reporting of an grayed representation kind icon that doesn't exist.
		 */
		@Test
		@OverlayFile(value = "bug570097-models/BookStore-missingGrayedIcon.architecture", path = "resources/BookStore.architecture")
		public void unresolvedGrayedIconResourceURI() {
			final List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$

			assertThat(modelMarkers, hasItem(both(isMarkerSeverity(IMarker.SEVERITY_ERROR)).and(isMarkerMessage(containsString("no-such-icon_d.png"))))); //$NON-NLS-1$
		}

		/**
		 * Test the reporting of an icon URI that is unparsable as a URI.
		 */
		@Test
		@OverlayFile(value = "bug570097-models/BookStore-invalidIcon.architecture", path = "resources/BookStore.architecture")
		public void invalidIconResourceURI() {
			final List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$

			assertThat(modelMarkers, hasItem(both(isMarkerSeverity(IMarker.SEVERITY_ERROR)).and(isMarkerMessage(containsString("Invalid icon URI"))))); //$NON-NLS-1$
		}

		/**
		 * Test the reporting of an Architecture Context ID that doesn't match the registration of one of its element type sets.
		 */
		@Test
		@OverlayFile(value = "bug542945/plugin-typesWrongContextID.xml", path = "plugin.xml")
		public void clientContextIDMismatch() {
			final List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$

			assertThat(modelMarkers, hasItem(both(isMarkerSeverity(IMarker.SEVERITY_WARNING)).and(
					isMarkerMessage(containsString("is registered to a different context"))))); //$NON-NLS-1$
		}

		/**
		 * Test that no problem is reported for an element types configuration set that is registered to another
		 * client context ID but is also registered explicitly to our Architecture Context.
		 */
		@Test
		@OverlayFile(value = "bug542945/plugin-typesMultiContextIDs.xml", path = "plugin.xml")
		public void multipleClientContexts() {
			final List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$

			assertThat(modelMarkers, not(hasItem(isMarkerMessage(containsString("is registered to a different context"))))); //$NON-NLS-1$
		}
	}

}

Back to the top