Skip to main content
summaryrefslogtreecommitdiffstats
blob: d351bcf21ba39e4d4bc423432db92f24aff5f7d2 (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
/*******************************************************************************
 * 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 com.google.common.collect.Iterables.size;
import static org.junit.Assert.assertEquals;

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

import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.provider.MatchItemProvider;
import org.eclipse.emf.compare.provider.spec.MatchItemProviderSpec;
import org.eclipse.emf.compare.tests.edit.data.ecore.a1.EcoreA1InputData;
import org.junit.Before;
import org.junit.Test;

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

	private MatchItemProvider itemProvider;

	@Override
	@Before
	public void before() throws IOException {
		super.before();
		itemProvider = (MatchItemProviderSpec)compareItemProviderAdapterFactory.createMatchAdapter();
	}

	@Test
	public void testGetChildren_EcoreA1() throws IOException {
		Match ePackageMatch = getEcoreA1_EPackageMatch();

		Collection<?> ePackageMatchChildren = itemProvider.getChildren(ePackageMatch);
		assertEquals(18, ePackageMatchChildren.size());
		assertEquals(4, size(filter(ePackageMatchChildren, Diff.class)));
		assertEquals(14, size(filter(ePackageMatchChildren, Match.class)));
	}

	static Match getEcoreA1_EPackageMatch() throws IOException {
		Comparison comparison = getComparison(new EcoreA1InputData());

		List<Match> matches = comparison.getMatches();
		Match ePackageMatch = matches.get(0);
		return ePackageMatch;
	}

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

		Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
		Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
				"AudioVisualItem");
		Collection<?> audioVisualItem_MatchChildren = itemProvider.getChildren(audioVisualItem_Match);

		assertEquals(4, audioVisualItem_MatchChildren.size());
		assertEquals(2, size(filter(audioVisualItem_MatchChildren, Diff.class)));
		assertEquals(2, size(filter(audioVisualItem_MatchChildren, Match.class)));
	}

	@Test
	public void testGetChildren_AudioVisualItem_lenght() throws IOException {
		Match ePackageMatch = getEcoreA1_EPackageMatch();

		Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
		Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
				"AudioVisualItem");
		Collection<?> audioVisualItem_MatchChildren = itemProvider.getChildren(audioVisualItem_Match);
		Match audioVisualItem_legnth_Match = getMatchWithFeatureValue(audioVisualItem_MatchChildren, "name",
				"length");
		Collection<?> audioVisualItem_legnth_MatchChildren = itemProvider
				.getChildren(audioVisualItem_legnth_Match);

		assertEquals(2, audioVisualItem_legnth_MatchChildren.size());
		assertEquals(2, size(filter(audioVisualItem_legnth_MatchChildren, Diff.class)));
		assertEquals(0, size(filter(audioVisualItem_legnth_MatchChildren, Match.class)));
	}

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

		Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
		Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book");
		Collection<?> book_MatchChildren = itemProvider.getChildren(book_Match);

		assertEquals(6, book_MatchChildren.size());
		assertEquals(3, size(filter(book_MatchChildren, Diff.class)));
		assertEquals(3, size(filter(book_MatchChildren, Match.class)));
	}

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

		Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
		Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory");
		Collection<?> bookCategory_MatchChildren = itemProvider.getChildren(bookCategory_Match);

		assertEquals(7, bookCategory_MatchChildren.size());
		assertEquals(4, size(filter(bookCategory_MatchChildren, Diff.class)));
		assertEquals(3, size(filter(bookCategory_MatchChildren, Match.class)));
	}

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

		Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
		Match borrowable_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Borrowable");
		Collection<?> borrowable_MatchChildren = itemProvider.getChildren(borrowable_Match);

		assertEquals(3, borrowable_MatchChildren.size());
		assertEquals(1, size(filter(borrowable_MatchChildren, Diff.class)));
		assertEquals(2, size(filter(borrowable_MatchChildren, Match.class)));
	}

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

		Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
		Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person");
		Collection<?> person_MatchChildren = itemProvider.getChildren(person_Match);

		assertEquals(3, person_MatchChildren.size());
		assertEquals(3, size(filter(person_MatchChildren, Diff.class)));
		assertEquals(0, size(filter(person_MatchChildren, Match.class)));
	}
}

Back to the top