Skip to main content
summaryrefslogtreecommitdiffstats
blob: 61aafd7b037198adfcd834c7774cf3f0c7ccb78e (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
193
194
195
196
197
198
/*******************************************************************************
 * Copyright (c) 2012 Obeo.
 * 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:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.compare.tests.edit;

import static com.google.common.collect.Iterables.filter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Collection;

import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.ecore.EClass;
import org.junit.Test;

/**
 * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
 */
public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItemProviderAdapter {

	@Test
	public void testGetChildren_AudioVisualItem() throws IOException {
		Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch)
				.getChildren(ePackageMatch);
		Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", //$NON-NLS-1$
				"AudioVisualItem"); //$NON-NLS-1$
		Collection<?> audioVisualItem_MatchChildren = adaptAsITreeItemContentProvider(audioVisualItem_Match)
				.getChildren(audioVisualItem_Match);

		ReferenceChange titleReferenceChange = getReferenceChangeWithFeatureValue(
				audioVisualItem_MatchChildren, "name", "title"); //$NON-NLS-1$ //$NON-NLS-2$

		Collection<?> titleReferenceChange_Children = adaptAsITreeItemContentProvider(titleReferenceChange)
				.getChildren(titleReferenceChange);

		assertEquals(0, titleReferenceChange_Children.size());
	}

	@Test
	public void testGetChildren_Book() throws IOException {
		Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch)
				.getChildren(ePackageMatch);
		Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book"); //$NON-NLS-1$ //$NON-NLS-2$
		Collection<?> book_MatchChildren = adaptAsITreeItemContentProvider(book_Match)
				.getChildren(book_Match);

		ReferenceChange subtitleReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren,
				"name", "subtitle"); //$NON-NLS-1$ //$NON-NLS-2$

		Collection<?> subtitleReferenceChange_Children = adaptAsITreeItemContentProvider(
				subtitleReferenceChange).getChildren(subtitleReferenceChange);

		assertEquals(0, subtitleReferenceChange_Children.size());
	}

	@Test
	public void testGetChildren_Borrowable() throws IOException {
		Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch)
				.getChildren(ePackageMatch);
		Match borrowableCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", //$NON-NLS-1$
				"Borrowable"); //$NON-NLS-1$
		Collection<?> borrowable_MatchChildren = adaptAsITreeItemContentProvider(borrowableCategory_Match)
				.getChildren(borrowableCategory_Match);

		assertEquals(3, borrowable_MatchChildren.size());
	}

	@Test
	public void testGetChildren_BookCategory() throws IOException {
		Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch)
				.getChildren(ePackageMatch);
		Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory"); //$NON-NLS-1$ //$NON-NLS-2$
		Collection<?> bookCategory_MatchChildren = adaptAsITreeItemContentProvider(bookCategory_Match)
				.getChildren(bookCategory_Match);

		ReferenceChange dictionaryReferenceChange = getReferenceChangeWithFeatureValue(
				bookCategory_MatchChildren, "name", "Dictionary"); //$NON-NLS-1$ //$NON-NLS-2$
		ReferenceChange encyclopediaReferenceChange = getReferenceChangeWithFeatureValue(
				bookCategory_MatchChildren, "name", "Encyclopedia"); //$NON-NLS-1$ //$NON-NLS-2$
		ReferenceChange mangaReferenceChange = getReferenceChangeWithFeatureValue(bookCategory_MatchChildren,
				"name", "Manga"); //$NON-NLS-1$ //$NON-NLS-2$
		ReferenceChange manhwaReferenceChange = getReferenceChangeWithFeatureValue(bookCategory_MatchChildren,
				"name", "Manhwa"); //$NON-NLS-1$ //$NON-NLS-2$

		assertTrue(adaptAsITreeItemContentProvider(dictionaryReferenceChange)
				.getChildren(dictionaryReferenceChange).isEmpty());
		assertTrue(adaptAsITreeItemContentProvider(encyclopediaReferenceChange)
				.getChildren(encyclopediaReferenceChange).isEmpty());
		assertTrue(adaptAsITreeItemContentProvider(mangaReferenceChange).getChildren(mangaReferenceChange)
				.isEmpty());
		assertTrue(adaptAsITreeItemContentProvider(manhwaReferenceChange).getChildren(manhwaReferenceChange)
				.isEmpty());
	}

	@Test
	public void testGetChildren_Magazine1() throws IOException {
		Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch)
				.getChildren(ePackageMatch);

		Collection<?> magazineChildren = null;
		for (ReferenceChange referenceChange : filter(ePackage_MatchChildren, ReferenceChange.class)) {
			EClass eClass = (EClass)referenceChange.getValue();
			if ("Magazine".equals(eClass.getName()) //$NON-NLS-1$
					&& "CirculatingItem".equals(eClass.getESuperTypes().get(0).getName())) { //$NON-NLS-1$
				magazineChildren = adaptAsITreeItemContentProvider(referenceChange)
						.getChildren(referenceChange);
				assertEquals(0, magazineChildren.size());
				break;
			}
		}
	}

	@Test
	public void testGetChildren_Magazine2() throws IOException {
		Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch)
				.getChildren(ePackageMatch);

		Collection<?> magazineChildren = null;
		for (ReferenceChange referenceChange : filter(ePackage_MatchChildren, ReferenceChange.class)) {
			EClass eClass = (EClass)referenceChange.getValue();
			if ("Magazine".equals(eClass.getName()) //$NON-NLS-1$
					&& "Periodical".equals(eClass.getESuperTypes().get(0).getName())) { //$NON-NLS-1$
				magazineChildren = adaptAsITreeItemContentProvider(referenceChange)
						.getChildren(referenceChange);
				assertEquals(0, magazineChildren.size());
				break;
			}
		}
	}

	@Test
	public void testGetChildren_Periodical() throws IOException {
		Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch)
				.getChildren(ePackageMatch);
		ReferenceChange periodical_ReferenceChange = getReferenceChangeWithFeatureValue(
				ePackage_MatchChildren, "name", "Periodical"); //$NON-NLS-1$ //$NON-NLS-2$
		Collection<?> periodical_ReferenceChangeChildren = adaptAsITreeItemContentProvider(
				periodical_ReferenceChange).getChildren(periodical_ReferenceChange);

		assertEquals(0, periodical_ReferenceChangeChildren.size());
	}

	@Test
	public void testGetChildren_Person() throws IOException {
		Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch)
				.getChildren(ePackageMatch);
		Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person"); //$NON-NLS-1$ //$NON-NLS-2$
		Collection<?> person_MatchChildren = adaptAsITreeItemContentProvider(person_Match)
				.getChildren(person_Match);

		assertEquals(6, person_MatchChildren.size());

		ReferenceChange issuesPerYearChange = getReferenceChangeWithFeatureValue(person_MatchChildren, "name", //$NON-NLS-1$
				"firstName"); //$NON-NLS-1$
		Collection<?> firstNameChildren = adaptAsITreeItemContentProvider(issuesPerYearChange)
				.getChildren(issuesPerYearChange);
		assertEquals(0, firstNameChildren.size());
	}

	@Test
	public void testGetChildren_TitledItem() throws IOException {
		Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch)
				.getChildren(ePackageMatch);

		ReferenceChange titledItem_ReferenceChange = getReferenceChangeWithFeatureValue(
				ePackage_MatchChildren, "name", "TitledItem"); //$NON-NLS-1$ //$NON-NLS-2$
		Collection<?> titledItem_ReferenceChangeChildren = adaptAsITreeItemContentProvider(
				titledItem_ReferenceChange).getChildren(titledItem_ReferenceChange);
		assertEquals(0, titledItem_ReferenceChangeChildren.size());
	}
}

Back to the top