Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse')
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptAllCoreTests.java46
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jdtutility/DefaultAnnotationEditFormatterTests.java74
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java72
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java131
4 files changed, 323 insertions, 0 deletions
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptAllCoreTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptAllCoreTests.java
new file mode 100644
index 0000000000..59ef19a30b
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptAllCoreTests.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.core.tests.internal;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.jpt.core.tests.internal.content.java.mappings.JptCoreContentJavaMappingsTests;
+import org.eclipse.jpt.core.tests.internal.jdtutility.JptCoreJdtUtilityTests;
+import org.eclipse.jpt.core.tests.internal.model.JptCoreModelTests;
+import org.eclipse.jpt.core.tests.internal.platform.JptCorePlatformTests;
+
+/**
+ * Runs all JPT Core Tests. Currently we do not have a jpa.jar checked in to cvs.
+ * As a result we cannot run any tests that depend on that jar during the build. In
+ * our dev environments we should run JptAllCoreTests until we have jpa.jar checked in.
+ * In the build we should continue to run JptCoreTests.
+ */
+public class JptAllCoreTests {
+
+ public static Test suite() {
+ return suite(true);
+ }
+
+ public static Test suite(boolean all) {
+ String quantity = all ? "All" : "Most";
+ TestSuite suite = new TestSuite(quantity + " JPT Core Tests");
+ suite.addTest(JptCoreContentJavaMappingsTests.suite(all));
+ suite.addTest(JptCoreModelTests.suite(all));
+ suite.addTest(JptCoreJdtUtilityTests.suite(all));
+ suite.addTest(JptCorePlatformTests.suite(all));
+ return suite;
+ }
+
+ private JptAllCoreTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jdtutility/DefaultAnnotationEditFormatterTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jdtutility/DefaultAnnotationEditFormatterTests.java
new file mode 100644
index 0000000000..13d3d804db
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jdtutility/DefaultAnnotationEditFormatterTests.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.core.tests.internal.jdtutility;
+
+import org.eclipse.jpt.core.internal.jdtutility.DefaultAnnotationEditFormatter;
+import org.eclipse.jpt.utility.internal.ClassTools;
+
+public class DefaultAnnotationEditFormatterTests extends AnnotationTestCase {
+
+
+ // ********** TestCase behavior **********
+
+ public DefaultAnnotationEditFormatterTests(String name) {
+ super(name);
+ }
+
+
+ // ********** tests **********
+
+ public void testCommaLength() throws Exception {
+ assertEquals(1, this.commaLength(","));
+ assertEquals(1, this.commaLength(", "));
+ assertEquals(1, this.commaLength(", "));
+
+ assertEquals(2, this.commaLength(" ,"));
+ assertEquals(2, this.commaLength(" , "));
+ assertEquals(2, this.commaLength(" , "));
+
+ assertEquals(3, this.commaLength(" ,"));
+ assertEquals(3, this.commaLength(" , "));
+ assertEquals(3, this.commaLength(" , "));
+
+ assertEquals(0, this.commaLength(" ,,,"));
+ assertEquals(0, this.commaLength(" ,,, "));
+ assertEquals(0, this.commaLength(" , ,"));
+
+ assertEquals(0, this.commaLength(" ,x"));
+ assertEquals(0, this.commaLength(" ,x "));
+ assertEquals(0, this.commaLength(" , x"));
+
+ assertEquals(0, this.commaLength("x ,"));
+ assertEquals(0, this.commaLength("x , "));
+ assertEquals(0, this.commaLength("x , "));
+ }
+
+ private int commaLength(String s) {
+ Integer len = (Integer) ClassTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "commaLength", String.class, s);
+ return len.intValue();
+ }
+
+ public void testStringIsAnnotation() throws Exception {
+ assertTrue(this.stringIsAnnotation("@F"));
+ assertTrue(this.stringIsAnnotation("@Foo"));
+ assertTrue(this.stringIsAnnotation("@org.bar.Foo"));
+
+ assertFalse(this.stringIsAnnotation(""));
+ assertFalse(this.stringIsAnnotation("@"));
+ assertFalse(this.stringIsAnnotation("Foo"));
+ assertFalse(this.stringIsAnnotation("Foo@"));
+ }
+
+ private boolean stringIsAnnotation(String s) {
+ Boolean b = (Boolean) ClassTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "stringIsAnnotation", String.class, s);
+ return b.booleanValue();
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java
new file mode 100644
index 0000000000..1057c85361
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.core.tests.internal.platform;
+
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jpt.core.internal.JpaPlatformRegistry;
+import org.eclipse.jpt.core.internal.JptCorePlugin;
+import org.eclipse.jpt.core.tests.extension.resource.ExtensionTestPlugin;
+import org.eclipse.jpt.core.tests.extension.resource.TestJpaPlatform;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+
+public class JpaPlatformExtensionTests extends TestCase
+{
+ public static final String TEST_PLATFORM_ID = TestJpaPlatform.PLATFORM_ID;
+ public static final String TEST_PLATFORM_LABEL = "Test Jpa Platform";
+
+ public JpaPlatformExtensionTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ verifyExtensionTestProjectExists();
+ }
+
+ public static void verifyExtensionTestProjectExists() {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint =
+ registry.getExtensionPoint(JptCorePlugin.PLUGIN_ID, "jpaPlatform");
+ IExtension[] extensions = extensionPoint.getExtensions();
+ boolean extensionFound = false;
+ for (IExtension extension : extensions) {
+ if (extension.getContributor().getName().equals(ExtensionTestPlugin.PLUGIN_ID)) {
+ extensionFound = true;
+ }
+ }
+ if (!extensionFound) {
+ throw new RuntimeException("Missing Extension " + TEST_PLATFORM_ID + ". The ExtensionTestProject plugin must be in your testing workspace.");
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testAllJpaPlatformIds() {
+ assertTrue(CollectionTools.size(JpaPlatformRegistry.instance().allJpaPlatformIds()) >= 2);
+ }
+
+ public void testJpaPlatformLabel() {
+ assertEquals(TEST_PLATFORM_LABEL, JpaPlatformRegistry.instance().jpaPlatformLabel(TEST_PLATFORM_ID));
+ }
+
+ public void testJpaPlatform() {
+ assertNotNull(JpaPlatformRegistry.instance().jpaPlatform(TEST_PLATFORM_ID));
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java
new file mode 100644
index 0000000000..55fe02a6b4
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.core.tests.internal.platform;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.core.internal.IJpaPlatform;
+import org.eclipse.jpt.core.internal.IJpaProject;
+import org.eclipse.jpt.core.internal.IMappingKeys;
+import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMappingProvider;
+import org.eclipse.jpt.core.internal.content.java.IJavaTypeMappingProvider;
+import org.eclipse.jpt.core.internal.content.java.mappings.JavaBasicProvider;
+import org.eclipse.jpt.core.internal.content.java.mappings.JavaEntityProvider;
+import org.eclipse.jpt.core.internal.platform.generic.GenericJpaFactory;
+import org.eclipse.jpt.core.internal.platform.generic.GenericPlatform;
+import org.eclipse.jpt.core.tests.extension.resource.ExtensionTestPlugin;
+import org.eclipse.jpt.core.tests.extension.resource.TestAttributeMappingProvider;
+import org.eclipse.jpt.core.tests.extension.resource.TestJpaFactory;
+import org.eclipse.jpt.core.tests.extension.resource.TestJpaPlatform;
+import org.eclipse.jpt.core.tests.extension.resource.TestTypeMappingProvider;
+import org.eclipse.jpt.core.tests.internal.ProjectUtility;
+import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject;
+
+public class JpaPlatformTests extends TestCase
+{
+ protected TestJpaProject testProject;
+
+ protected static final String PROJECT_NAME = "ExtensionTestProject";
+ protected static final String PACKAGE_NAME = "extension.test";
+
+ public static final String TEST_PLUGIN_CLASS = ExtensionTestPlugin.class.getName();
+ public static final String TEST_PLUGIN_ID = "org.eclipse.jpt.core.tests.extension.resource";
+
+ public static final String TEST_PLATFORM_ID = TestJpaPlatform.PLATFORM_ID;
+ public static final String TEST_PLATFORM_CLASS = TestJpaPlatform.class.getName();
+ public static final String TEST_PLATFORM_LABEL = "Test Jpa Platform";
+ public static final String TEST_JPA_FACTORY = TestJpaFactory.class.getName();
+ public static final String TEST_TYPE_MAPPING_PROVIDER_CLASS = TestTypeMappingProvider.class.getName();
+ public static final String TEST_ATTRIBUTE_MAPPING_PROVIDER_CLASS = TestAttributeMappingProvider.class.getName();
+
+ public JpaPlatformTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ JpaPlatformExtensionTests.verifyExtensionTestProjectExists();
+ ProjectUtility.deleteAllProjects();
+ testProject = this.buildJpaProject(TestJpaProject.uniqueProjectName(PROJECT_NAME), false); // false = no auto-build
+ }
+
+ protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild) throws Exception {
+ return new TestJpaProject(projectName, autoBuild); // false = no auto-build
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ testProject = null;
+ ProjectUtility.deleteAllProjects();
+// testProject.dispose();
+ super.tearDown();
+ }
+
+ protected IJpaProject jpaProject() {
+ return this.testProject.getJpaProject();
+ }
+
+ public void testSetPlatform() {
+ assertTrue(jpaPlatform() instanceof GenericPlatform);
+
+ jpaProject().setPlatform(TEST_PLATFORM_ID);
+
+ assertTrue(jpaPlatform().getClass().getName().equals(TEST_PLATFORM_CLASS));
+ }
+
+ public void testGetJpaFactory() {
+ assertTrue(jpaPlatform().getJpaFactory() instanceof GenericJpaFactory);
+ jpaProject().setPlatform(TEST_PLATFORM_ID);
+
+ assertTrue(jpaPlatform().getJpaFactory().getClass().getName().equals(TEST_JPA_FACTORY));
+ }
+
+ public void testJavaTypeMappingProvider() {
+ IJavaTypeMappingProvider provider = jpaProject().getPlatform().javaTypeMappingProvider(IMappingKeys.ENTITY_TYPE_MAPPING_KEY);
+ assertTrue(provider instanceof JavaEntityProvider);
+
+ provider = jpaProject().getPlatform().javaTypeMappingProvider("test");
+ assertNull(provider);
+
+ jpaProject().setPlatform(TEST_PLATFORM_ID);
+
+ provider = jpaProject().getPlatform().javaTypeMappingProvider(IMappingKeys.ENTITY_TYPE_MAPPING_KEY);
+ assertTrue(provider instanceof JavaEntityProvider);
+
+ provider = jpaProject().getPlatform().javaTypeMappingProvider("test");
+ assertTrue(provider.getClass().getName().equals(TEST_TYPE_MAPPING_PROVIDER_CLASS));
+ }
+
+ public void testJavaAttributeMappingProvider() {
+ IJavaAttributeMappingProvider provider = jpaProject().getPlatform().javaAttributeMappingProvider(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(provider instanceof JavaBasicProvider);
+ boolean exceptionCaught = false;
+ try {
+ provider = jpaProject().getPlatform().javaAttributeMappingProvider("test");
+ }
+ catch (IllegalArgumentException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+
+ jpaProject().setPlatform(TEST_PLATFORM_ID);
+
+ provider = jpaProject().getPlatform().javaAttributeMappingProvider(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(provider instanceof JavaBasicProvider);
+
+ provider = jpaProject().getPlatform().javaAttributeMappingProvider("test");
+ assertTrue(provider.getClass().getName().equals(TEST_ATTRIBUTE_MAPPING_PROVIDER_CLASS));
+ }
+
+ private IJpaPlatform jpaPlatform() {
+ return jpaProject().jpaPlatform();
+ }
+}

Back to the top