Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d55308b83ac27ac7137801e030c7a8cfc9f107e9 (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
/*******************************************************************************
 * Copyright (c) 2011 Formal Mind GmbH and University of Dusseldorf.
 * 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:
 *     Michael Jastram - initial API and implementation
 ******************************************************************************/

package org.eclipse.rmf.reqif10.provider;

import static org.junit.Assert.assertEquals;

import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.rmf.reqif10.AttributeDefinitionString;
import org.eclipse.rmf.reqif10.ReqIF;
import org.eclipse.rmf.reqif10.ReqIF10Factory;
import org.eclipse.rmf.reqif10.ReqIF10Package;
import org.eclipse.rmf.reqif10.SpecHierarchy;
import org.eclipse.rmf.reqif10.SpecObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * A test case for the model object '<em><b>Spec Hierarchy</b></em>'.
 */
public class SpecHierarchyTest extends IdentifiableTest {

	/**
	 * Returns the fixture for this Spec Hierarchy test case.
	 */
	@Override
	protected SpecHierarchy getFixture() {
		return (SpecHierarchy)fixture;
	}

	/**
	 * @see junit.framework.TestCase#setUp()
	 */
	@Before
	public void setUpSpecHierarchyTest() throws Exception {
		setFixture(ReqIF10Factory.eINSTANCE.createSpecHierarchy());
	}

	/**
	 * @see junit.framework.TestCase#tearDown()
	 */
	@After
	public void tearDownSpecHierarchyTest() throws Exception {
		setFixture(null);
	}
	
	/**
	 * We test that the properties for the SpecObject appear on the SpecHierarchy.
	 */
	@Test
	public void testPropertiesOfSpecElementWithAttribute() throws URISyntaxException {
		ReqIF reqif = getTestReqif("simple.reqif");
		setViaCommand(reqif.getCoreContent().getSpecifications().get(0), ReqIF10Package.Literals.SPECIFICATION__CHILDREN, getFixture());
		SpecObject specObject = reqif.getCoreContent().getSpecObjects().get(0);
		getFixture().setObject(specObject);
		ItemProviderAdapter ip = getItemProvider(getFixture());

		Set<String> expected = new HashSet<String>();
		for (IItemPropertyDescriptor prop: ip.getPropertyDescriptors(getFixture())) {
			expected.add(prop.getCategory(getFixture()) + "-" + prop.getDisplayName(getFixture()));			
		}
		
		AttributeDefinitionString ad = ReqIF10Factory.eINSTANCE.createAttributeDefinitionString();
		adapterFactory.adapt(ad, IItemLabelProvider.class);
		adapterFactory.adapt(specObject.getType(), IItemLabelProvider.class);
		adapterFactory.adapt(specObject, IItemLabelProvider.class);
		adapterFactory.adapt(getFixture(), IItemLabelProvider.class);

		ad.setLongName("New");
		setViaCommand(specObject.getType(), ReqIF10Package.Literals.SPEC_TYPE__SPEC_ATTRIBUTES, ad);
		
		assertEquals(expected.size() + 1, ip.getPropertyDescriptors(getFixture()).size());
		
		// Set of actuals
		Set<String> actual = new HashSet<String>();
		for (IItemPropertyDescriptor prop: ip.getPropertyDescriptors(getFixture())) {
			actual.add(prop.getCategory(getFixture()) + "-" + prop.getDisplayName(getFixture()));			
		}

		// Set of expected
		expected.add("Example SpecType-New");
		assertEquals(expected, actual);
	}


} //SpecHierarchyTest

Back to the top