Skip to main content
summaryrefslogtreecommitdiffstats
blob: e69c8efae514674afb75bbd178b3145069b55531 (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
/*******************************************************************************
* Copyright (c) 2008, 2009 Oracle. 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:
*     Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.general;

import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties;
import org.eclipse.jpt.eclipselink.core.context.persistence.general.GeneralProperties;
import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase;
import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;

/**
 *  GeneralAdapterTests
 */
@SuppressWarnings("nls")
public class GeneralPropertiesAdapterTests extends EclipseLinkPersistenceUnitTestCase
{
	private GeneralProperties generalProperties;

	public static final String EXCLUDE_ECLIPSELINK_ORM_KEY = GeneralProperties.ECLIPSELINK_EXCLUDE_ECLIPSELINK_ORM;
	public static final Boolean EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE = false;
	public static final Boolean EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE_2 = ! EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE;

	
	public GeneralPropertiesAdapterTests(String name) {
		super(name);
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		this.generalProperties = this.subject.getGeneralProperties();
		PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener();
		
		this.generalProperties.addPropertyChangeListener(GeneralProperties.EXCLUDE_ECLIPSELINK_ORM_PROPERTY, propertyChangeListener);

		this.clearEvent();
	}

	/**
	 * Initializes directly the PU properties before testing.
	 */
	@Override
	protected void populatePu() {
		this.modelPropertiesSizeOriginal = 1;
		this.propertiesTotal = this.modelPropertiesSizeOriginal + 2; // misc properties
		this.modelPropertiesSize = this.modelPropertiesSizeOriginal;
		
		this.persistenceUnitSetProperty("misc.property.1", "value.1");
		this.persistenceUnitSetProperty(EXCLUDE_ECLIPSELINK_ORM_KEY, EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE.toString());
		this.persistenceUnitSetProperty("misc.property.2", "value.2");

		return;
	}

	
	// ********** ExcludeEclipselinkOrm tests **********
	public void testSetExcludeEclipselinkOrm() throws Exception {
		this.verifyModelInitialized(
			EXCLUDE_ECLIPSELINK_ORM_KEY,
			EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE);
		this.verifySetProperty(
			EXCLUDE_ECLIPSELINK_ORM_KEY,
			EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE,
			EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE_2);
	}

	public void testAddRemoveExcludeEclipselinkOrm() throws Exception {
		this.verifyAddRemoveProperty(
			EXCLUDE_ECLIPSELINK_ORM_KEY,
			EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE,
			EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE_2);
	}



	// ********** get/set property **********
	@Override
	protected Object getProperty(String propertyName) throws NoSuchFieldException {
		Object modelValue = null;
		if (propertyName.equals(GeneralProperties.EXCLUDE_ECLIPSELINK_ORM_PROPERTY))
			modelValue = this.generalProperties.getExcludeEclipselinkOrm();
		else
			this.throwMissingDefinition("getProperty", propertyName);
		return modelValue;
	}

	@Override
	protected void setProperty(String propertyName, Object newValue) throws Exception {
		if (propertyName.equals(GeneralProperties.EXCLUDE_ECLIPSELINK_ORM_PROPERTY))
			this.generalProperties.setExcludeEclipselinkOrm((Boolean) newValue);
		else
			this.throwMissingDefinition("setProperty", propertyName);
	}
	
	@Override
	protected PersistenceUnitProperties getModel() {
		return this.generalProperties;
	}
}

Back to the top