Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 13f9ae9f518cd50acd0e27f0c886d3b97f4a7974 (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
/*
 * Copyright (c) 2014 CEA and others.
 *
 * 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:
 *   Christian W. Damus (CEA) - Initial API and implementation
 *
 */
package org.eclipse.papyrus.infra.emf.readonly;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import org.eclipse.papyrus.infra.emf.readonly.tests.PapyrusROEditingDomainFixture;
import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
import org.eclipse.uml2.uml.Type;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.google.common.collect.Iterators;


/**
 * This is the ReadOnlyTesterTest type. Enjoy.
 */
@JavaResource("Bug323802.uml")
public class ReadOnlyTesterTest extends AbstractPapyrusTest {

	@Rule
	public final PapyrusROEditingDomainFixture domain = new PapyrusROEditingDomainFixture();

	private final ProjectFixture project = domain.getProject();

	private ReadOnlyTester fixture;

	@Test
	public void testAsBoolean() {
		assertThat(fixture.asBoolean(true), is(true));
		assertThat(fixture.asBoolean(false), is(false));
		assertThat(fixture.asBoolean("hello"), is(true));
		assertThat(fixture.asBoolean(null), is(true));
	}

	@Test
	public void testIsReadOnly() {
		assertThat(fixture.testIsReadOnly(Iterators.singletonIterator(domain.getModel()), false), is(true));

		Type string = domain.getModel().getImportedPackages().get(0).getOwnedType("String");
		assertThat(fixture.testIsReadOnly(Iterators.singletonIterator(string), true), is(true));

		project.setReadOnly(domain.getModelResource());
		assertThat(fixture.testIsReadOnly(Iterators.singletonIterator(domain.getModel()), true), is(true));
	}

	@Test
	public void testCanMakeWritable() {
		// If it's already writable, well, then it's trivially easy to make it writable
		assertThat(fixture.canMakeWritable(Iterators.singletonIterator(domain.getModel()), true), is(true));

		Type string = domain.getModel().getImportedPackages().get(0).getOwnedType("String");
		assertThat(fixture.canMakeWritable(Iterators.singletonIterator(string), true), is(false));

		project.setReadOnly(domain.getModelResource());
		assertThat(fixture.canMakeWritable(Iterators.singletonIterator(domain.getModel()), true), is(true));
	}

	//
	// Test framework
	//

	@Before
	public void createFixture() throws Exception {
		fixture = new ReadOnlyTester();
	}

	@After
	public void destroyFixture() {
		fixture = null;
	}

}

Back to the top