Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortle2012-04-02 22:58:58 +0000
committertle2012-04-02 22:58:58 +0000
commitd9ada50aaeac0e395b841702a8f7dc12567b11b2 (patch)
tree7a24a1612cd2ac0e905db97252dd0bb38eb37003 /jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt
parent07d7b38b1f10a43231d2c0c2728c44875506b0e7 (diff)
downloadwebtools.dali-d9ada50aaeac0e395b841702a8f7dc12567b11b2.tar.gz
webtools.dali-d9ada50aaeac0e395b841702a8f7dc12567b11b2.tar.xz
webtools.dali-d9ada50aaeac0e395b841702a8f7dc12567b11b2.zip
Added preference metadata tests.
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt')
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/JptJpaCoreTests.java2
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaEntityGenMetadataTests.java66
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaJpqlMetadataTests.java59
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaMetadataTests.java101
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaValidationMetadataTests.java83
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JptJpaCoreMetadataTests.java33
6 files changed, 344 insertions, 0 deletions
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/JptJpaCoreTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/JptJpaCoreTests.java
index f6e3de9f6e..85e0c1a8a5 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/JptJpaCoreTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/JptJpaCoreTests.java
@@ -13,6 +13,7 @@ import java.io.File;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.jpt.jpa.core.tests.internal.context.JptJpaCoreContextModelTests;
+import org.eclipse.jpt.jpa.core.tests.internal.metadata.JptJpaCoreMetadataTests;
import org.eclipse.jpt.jpa.core.tests.internal.model.JptJpaCoreModelTests;
import org.eclipse.jpt.jpa.core.tests.internal.projects.TestJpaProject;
import org.eclipse.jpt.jpa.core.tests.internal.resource.JptJpaCoreResourceModelTests;
@@ -33,6 +34,7 @@ public class JptJpaCoreTests {
suite.addTest(JptJpaCoreModelTests.suite());
suite.addTest(JptJpaCoreResourceModelTests.suite());
suite.addTest(JptJpaCoreContextModelTests.suite());
+ suite.addTest(JptJpaCoreMetadataTests.suite());
return suite;
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaEntityGenMetadataTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaEntityGenMetadataTests.java
new file mode 100644
index 0000000000..e21c902e3f
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaEntityGenMetadataTests.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+* Copyright (c) 2012 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.metadata;
+
+import junit.framework.Assert;
+
+import org.eclipse.jpt.jpa.core.prefs.JpaEntityGenPreferencesManager;
+
+/**
+ * JpaEntityGenMetadataTests
+ */
+public class JpaEntityGenMetadataTests extends JpaMetadataTests {
+
+ public static final String DEFAULT_PACKAGE_PREF_KEY = "entitygen.DEFAULT_PACKAGE"; //$NON-NLS-1$
+
+ public static final String DEFAULT_PACKAGE_TEST_VALUE = "test.model"; //$NON-NLS-1$
+
+ protected JpaEntityGenPreferencesManager projectPrefsManager;
+
+ // ********** constructor **********
+
+ public JpaEntityGenMetadataTests(String name) {
+ super(name);
+ }
+
+ // ********** overrides **********
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.projectPrefsManager = new JpaEntityGenPreferencesManager(this.getJavaProject().getProject());
+ Assert.assertNotNull(this.projectPrefsManager);
+ }
+
+ // ********** tests **********
+
+ public void testDefaultPackageWorkspaceMetadata() throws Exception {
+ JpaEntityGenPreferencesManager.setDefaultPackageWorkspacePreference(DEFAULT_PACKAGE_TEST_VALUE);
+ JpaEntityGenPreferencesManager.getLegacyWorkspacePreferences().flush();
+
+ String value = this.getWorkspacePrefs().get(DEFAULT_PACKAGE_PREF_KEY);
+ Assert.assertNotNull(value);
+ Assert.assertTrue(DEFAULT_PACKAGE_TEST_VALUE.equals(value));
+
+ JpaEntityGenPreferencesManager.removeLegacyWorkspacePreference(DEFAULT_PACKAGE_PREF_KEY);
+ }
+
+ public void testDefaultPackageProjectMetadata() throws Exception {
+
+ this.projectPrefsManager.setDefaultPackagePreference(DEFAULT_PACKAGE_TEST_VALUE);
+ this.projectPrefsManager.getLegacyProjectPreferences().flush();
+
+ String value = this.getProjectPrefs().get(DEFAULT_PACKAGE_PREF_KEY);
+ Assert.assertNotNull(value);
+ Assert.assertTrue(DEFAULT_PACKAGE_TEST_VALUE.equals(value));
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaJpqlMetadataTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaJpqlMetadataTests.java
new file mode 100644
index 0000000000..df1daea08d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaJpqlMetadataTests.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+* Copyright (c) 2012 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.metadata;
+
+import junit.framework.Assert;
+
+import org.eclipse.jpt.jpa.core.prefs.JpaEntityGenPreferencesManager;
+import org.eclipse.jpt.jpa.core.prefs.JpaJpqlPreferencesManager;
+
+/**
+ * JpaJpqlMetadataTests
+ */
+public class JpaJpqlMetadataTests extends JpaMetadataTests {
+
+ public static final String CASE_PREF_KEY = "jpqlIdentifier.CASE";
+ public static final String MATCH_FIRST_CHARACTER_CASE_PREF_KEY = "jpqlIdentifier.MATCH_FIRST_CHARACTER_CASE";
+
+ public static final String CASE_TEST_VALUE = JpaJpqlPreferencesManager.JPQL_IDENTIFIER_UPPERCASE_PREF_VALUE;
+ public static final boolean MATCH_FIRST_CHARACTER_CASE_TEST_VALUE = ! JpaJpqlPreferencesManager.DEFAULT_MATCH_FIRST_CHARACTER_CASE;
+
+ // ********** constructor **********
+
+ public JpaJpqlMetadataTests(String name) {
+ super(name);
+ }
+
+ // ********** tests **********
+
+ public void testIdentifiersCaseWorkspaceMetadata() throws Exception {
+ JpaJpqlPreferencesManager.setIdentifiersCaseWorkspacePreference(CASE_TEST_VALUE);
+ JpaJpqlPreferencesManager.getLegacyWorkspacePreferences().flush();
+
+ String value = this.getWorkspacePrefs().get(CASE_PREF_KEY);
+ Assert.assertNotNull(value);
+ Assert.assertTrue(CASE_TEST_VALUE.equals(value));
+
+ JpaEntityGenPreferencesManager.removeLegacyWorkspacePreference(CASE_PREF_KEY);
+ }
+
+ public void testMatchFirstCharacterCaseWorkspaceMetadata() throws Exception {
+ JpaJpqlPreferencesManager.setMatchFirstCharacterCaseWorkspacePreference(MATCH_FIRST_CHARACTER_CASE_TEST_VALUE);
+ JpaJpqlPreferencesManager.getLegacyWorkspacePreferences().flush();
+
+ String stringValue = this.getWorkspacePrefs().get(MATCH_FIRST_CHARACTER_CASE_PREF_KEY);
+ Assert.assertNotNull(stringValue);
+ boolean value = Boolean.valueOf(stringValue);
+ Assert.assertTrue(value == MATCH_FIRST_CHARACTER_CASE_TEST_VALUE);
+
+ JpaEntityGenPreferencesManager.removeLegacyWorkspacePreference(MATCH_FIRST_CHARACTER_CASE_PREF_KEY);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaMetadataTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaMetadataTests.java
new file mode 100644
index 0000000000..2997c41acc
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaMetadataTests.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+* Copyright (c) 2012 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.metadata;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+
+/**
+ * JpaMetadataTests
+ */
+public abstract class JpaMetadataTests extends AnnotationTestCase {
+
+ private static final String SETTINGS_DIR = ".settings/";
+ private static final String ECLIPSE_CORE_SETTINGS_DIR = ".metadata/.plugins/org.eclipse.core.runtime/" + SETTINGS_DIR;
+ public static final String PREFS_FILE_NAME = JptJpaCorePlugin.LEGACY_PLUGIN_ID + ".prefs";
+
+ protected IEclipsePreferences workspacePreferences;
+ private String eclipseCoreSettingsDir;
+ private String projectSettingsDir;
+
+ // ********** constructor **********
+
+ protected JpaMetadataTests(String name) {
+ super(name);
+ }
+
+ // ********** overrides **********
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ IPath workspacePath = this.getWorkspaceRoot().getLocation();
+ this.eclipseCoreSettingsDir = workspacePath + "/" + ECLIPSE_CORE_SETTINGS_DIR;
+
+ IPath projectPath = this.javaProject.getProject().getLocation();
+ this.projectSettingsDir = projectPath + "/" + SETTINGS_DIR;
+ }
+
+ // ********** preferences **********
+
+ protected Map<String, String> getWorkspacePrefs() {
+ return this.getSettings(this.eclipseCoreSettingsDir + PREFS_FILE_NAME);
+ }
+
+ protected Map<String, String> getProjectPrefs() {
+ return this.getSettings(this.projectSettingsDir + PREFS_FILE_NAME);
+ }
+
+ // ********** internal methods **********
+
+ private IWorkspaceRoot getWorkspaceRoot() {
+ return ResourcesPlugin.getWorkspace().getRoot();
+ }
+
+ private Map<String, String> getSettings(String settingsPath) {
+ Set<Entry<Object, Object>> settingsSet = null;
+ try {
+ settingsSet = this.loadMetadata(settingsPath);
+ }
+ catch (IOException e) {
+ throw new RuntimeException("Missing: " + settingsPath, e);
+ }
+
+ Map<String, String> settings = new HashMap<String, String>();
+ for(Entry<Object, Object> property : settingsSet) {
+ settings.put((String)property.getKey(), (String)property.getValue());
+ }
+ return settings;
+ }
+
+ private Set<Entry<Object, Object>> loadMetadata(String metadataPath) throws IOException {
+ FileInputStream stream = new FileInputStream(metadataPath);
+
+ Properties properties = new Properties();
+ properties.load(stream);
+ stream.close();
+
+ return properties.entrySet();
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaValidationMetadataTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaValidationMetadataTests.java
new file mode 100644
index 0000000000..00394e1e6f
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JpaValidationMetadataTests.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+* Copyright (c) 2012 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.metadata;
+
+import junit.framework.Assert;
+
+import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
+import org.eclipse.jpt.jpa.core.prefs.JpaValidationPreferencesManager;
+
+/**
+ * JpaValidationMetadataTests
+ */
+public class JpaValidationMetadataTests extends JpaMetadataTests {
+
+ public static final String WORKSPACE_OVERRIDEN_PREF_KEY = "workspace_preferences_overriden";
+ public static final String PERSISTENCE_NO_PERSISTENCE_UNIT_PREF_KEY = "problem." + JpaValidationMessages.PERSISTENCE_NO_PERSISTENCE_UNIT;
+
+ public static final boolean WORKSPACE_OVERRIDEN_TEST_VALUE = true;
+ public static final String PERSISTENCE_NO_PERSISTENCE_UNIT_TEST_VALUE = JpaValidationPreferencesManager.INFO;
+
+ protected JpaValidationPreferencesManager projectPrefsManager;
+
+ // ********** constructor **********
+
+ public JpaValidationMetadataTests(String name) {
+ super(name);
+ }
+
+ // ********** overrides **********
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.projectPrefsManager = new JpaValidationPreferencesManager(this.getJavaProject().getProject());
+ Assert.assertNotNull(this.projectPrefsManager);
+ }
+
+ // ********** tests **********
+
+ public void testWorkspaceLevelProblemMetadata() throws Exception {
+ JpaValidationPreferencesManager.setWorkspaceLevelProblemPreference(
+ JpaValidationMessages.PERSISTENCE_NO_PERSISTENCE_UNIT,
+ PERSISTENCE_NO_PERSISTENCE_UNIT_TEST_VALUE);
+ JpaValidationPreferencesManager.getLegacyWorkspacePreferences().flush();
+
+ String value = this.getWorkspacePrefs().get(PERSISTENCE_NO_PERSISTENCE_UNIT_PREF_KEY);
+ Assert.assertNotNull(value);
+ Assert.assertTrue(PERSISTENCE_NO_PERSISTENCE_UNIT_TEST_VALUE.equals(value));
+
+ JpaValidationPreferencesManager.removeLegacyWorkspacePreference(PERSISTENCE_NO_PERSISTENCE_UNIT_PREF_KEY);
+ }
+
+ public void testProjectHasSpecificOptionsMetadata() throws Exception {
+
+ this.projectPrefsManager.setProjectHasSpecificOptions(WORKSPACE_OVERRIDEN_TEST_VALUE);
+ this.projectPrefsManager.getLegacyProjectPreferences().flush();
+
+ String stringValue = this.getProjectPrefs().get(WORKSPACE_OVERRIDEN_PREF_KEY);
+ Assert.assertNotNull(stringValue);
+ boolean value = Boolean.valueOf(stringValue);
+ Assert.assertTrue(value == WORKSPACE_OVERRIDEN_TEST_VALUE);
+ }
+
+ public void testProjectLevelProblemMetadata() throws Exception {
+
+ this.projectPrefsManager.setProjectLevelProblemPreference(
+ JpaValidationMessages.PERSISTENCE_NO_PERSISTENCE_UNIT,
+ PERSISTENCE_NO_PERSISTENCE_UNIT_TEST_VALUE);
+ this.projectPrefsManager.getLegacyProjectPreferences().flush();
+
+ String value = this.getProjectPrefs().get(PERSISTENCE_NO_PERSISTENCE_UNIT_PREF_KEY);
+ Assert.assertNotNull(value);
+ Assert.assertTrue(PERSISTENCE_NO_PERSISTENCE_UNIT_TEST_VALUE.equals(value));
+ }
+} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JptJpaCoreMetadataTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JptJpaCoreMetadataTests.java
new file mode 100644
index 0000000000..41ba644d5c
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/metadata/JptJpaCoreMetadataTests.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+* Copyright (c) 2012 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.metadata;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * JptJpaCoreMetadataTests
+ */
+public class JptJpaCoreMetadataTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JptJpaCoreMetadataTests.class.getPackage().getName());
+ suite.addTestSuite(JpaEntityGenMetadataTests.class);
+ suite.addTestSuite(JpaJpqlMetadataTests.class);
+ suite.addTestSuite(JpaValidationMetadataTests.class);
+ return suite;
+ }
+
+ private JptJpaCoreMetadataTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+
+} \ No newline at end of file

Back to the top