Skip to main content
summaryrefslogtreecommitdiffstats
blob: a913b9e2297a14d0dbeb17ddcbbd3caf0aa483e6 (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
/*******************************************************************************
* Copyright (c) 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.jpa.core.tests.internal.jpa2.context.persistence;

import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnitProperties;
import org.eclipse.jpt.jpa.core.jpa2.context.persistence.connection.JpaConnection2_0;

/**
 *  GenericConnection2_0Tests
 */
@SuppressWarnings("nls")
public class Generic2_0ConnectionTests extends Generic2_0PersistenceUnitTests
{
	private JpaConnection2_0 connection;

	public static final String DRIVER_KEY = JpaConnection2_0.PERSISTENCE_JDBC_DRIVER;
	public static final String DRIVER_TEST_VALUE = "test";
	public static final String DRIVER_TEST_VALUE_2 = "test_2";
	
	public static final String URL_KEY = JpaConnection2_0.PERSISTENCE_JDBC_URL;
	public static final String URL_TEST_VALUE = "test";
	public static final String URL_TEST_VALUE_2 = "test_2";

	public static final String USER_KEY = JpaConnection2_0.PERSISTENCE_JDBC_USER;
	public static final String USER_TEST_VALUE = "test";
	public static final String USER_TEST_VALUE_2 = "test_2";

	public static final String PASSWORD_KEY = JpaConnection2_0.PERSISTENCE_JDBC_PASSWORD;
	public static final String PASSWORD_TEST_VALUE = "test";
	public static final String PASSWORD_TEST_VALUE_2 = "test_2";

	// ********** constructors **********
	public Generic2_0ConnectionTests(String name) {
		super(name);
	}

	// ********** behavior **********
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		this.connection = (JpaConnection2_0) this.subject.getConnection();
		PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener();

		this.connection.addPropertyChangeListener(JpaConnection2_0.DRIVER_PROPERTY, propertyChangeListener);
		this.connection.addPropertyChangeListener(JpaConnection2_0.URL_PROPERTY, propertyChangeListener);
		this.connection.addPropertyChangeListener(JpaConnection2_0.USER_PROPERTY, propertyChangeListener);
		this.connection.addPropertyChangeListener(JpaConnection2_0.PASSWORD_PROPERTY, propertyChangeListener);
		
		this.clearEvent();
	}

	/**
	 * Initializes directly the PersistenceUnit properties before testing.
	 */
	@Override
	protected void populatePu() {
		this.modelPropertiesSizeOriginal = 4; // PersistenceUnit properties
		this.propertiesTotal = this.modelPropertiesSizeOriginal + 1; // 1 misc properties
		this.modelPropertiesSize = this.modelPropertiesSizeOriginal;
		
		// Initializes PersistenceUnit properties
		this.persistenceUnitSetProperty("misc.property.1", "value.1");
		this.persistenceUnitSetProperty(DRIVER_KEY, DRIVER_TEST_VALUE.toString());
		this.persistenceUnitSetProperty(URL_KEY, URL_TEST_VALUE.toString());
		this.persistenceUnitSetProperty(USER_KEY, USER_TEST_VALUE.toString());
		this.persistenceUnitSetProperty(PASSWORD_KEY, PASSWORD_TEST_VALUE.toString());

	}

	@Override
	protected PersistenceUnitProperties getModel() {
		return this.connection;
	}

	@Override
	protected Object getProperty(String propertyName) throws NoSuchFieldException {
		Object modelValue = null;
		if (propertyName.equals(JpaConnection2_0.DRIVER_PROPERTY))
			modelValue = this.connection.getDriver();
		else if (propertyName.equals(JpaConnection2_0.URL_PROPERTY))
			modelValue = this.connection.getUrl();
		else if (propertyName.equals(JpaConnection2_0.USER_PROPERTY))
			modelValue = this.connection.getUser();
		else if (propertyName.equals(JpaConnection2_0.PASSWORD_PROPERTY))
			modelValue = this.connection.getPassword();
		else
			this.throwMissingDefinition("getProperty", propertyName);
		return modelValue;
	}


	@Override
	protected void setProperty(String propertyName, Object newValue) throws Exception {
		if (propertyName.equals(JpaConnection2_0.DRIVER_PROPERTY))
			this.connection.setDriver((String) newValue);
		else if (propertyName.equals(JpaConnection2_0.URL_PROPERTY))
			this.connection.setUrl((String) newValue);
		else if (propertyName.equals(JpaConnection2_0.USER_PROPERTY))
			this.connection.setUser((String) newValue);
		else if (propertyName.equals(JpaConnection2_0.PASSWORD_PROPERTY))
			this.connection.setPassword((String) newValue);
		else
			this.throwMissingDefinition("setProperty", propertyName);
	}

	// ********** Driver tests **********
	public void testSetDriver() throws Exception {
		this.verifyModelInitialized(
			DRIVER_KEY,
			DRIVER_TEST_VALUE);
		this.verifySetProperty(
			DRIVER_KEY,
			DRIVER_TEST_VALUE,
			DRIVER_TEST_VALUE_2);
	}

	public void testAddRemoveDriver() throws Exception {
		this.verifyAddRemoveProperty(
			DRIVER_KEY,
			DRIVER_TEST_VALUE,
			DRIVER_TEST_VALUE_2);
	}

	// ********** Url tests **********
	public void testSetUrl() throws Exception {
		this.verifyModelInitialized(
			URL_KEY,
			URL_TEST_VALUE);
		this.verifySetProperty(
			URL_KEY,
			URL_TEST_VALUE,
			URL_TEST_VALUE_2);
	}

	public void testAddRemoveUrl() throws Exception {
		this.verifyAddRemoveProperty(
			URL_KEY,
			URL_TEST_VALUE,
			URL_TEST_VALUE_2);
	}

	// ********** User tests **********
	public void testSetUser() throws Exception {
		this.verifyModelInitialized(
			USER_KEY,
			USER_TEST_VALUE);
		this.verifySetProperty(
			USER_KEY,
			USER_TEST_VALUE,
			USER_TEST_VALUE_2);
	}

	public void testAddRemoveUser() throws Exception {
		this.verifyAddRemoveProperty(
			USER_KEY,
			USER_TEST_VALUE,
			USER_TEST_VALUE_2);
	}

	// ********** Password tests **********
	public void testSetPassword() throws Exception {
		this.verifyModelInitialized(
			PASSWORD_KEY,
			PASSWORD_TEST_VALUE);
		this.verifySetProperty(
			PASSWORD_KEY,
			PASSWORD_TEST_VALUE,
			PASSWORD_TEST_VALUE_2);
	}

	public void testAddRemovePassword() throws Exception {
		this.verifyAddRemoveProperty(
			PASSWORD_KEY,
			PASSWORD_TEST_VALUE,
			PASSWORD_TEST_VALUE_2);
	}
	
}

Back to the top