diff options
author | pfullbright | 2011-12-16 17:28:05 +0000 |
---|---|---|
committer | pfullbright | 2011-12-16 17:28:05 +0000 |
commit | 4e596fa171c6837f93b7271ba807c310464090dd (patch) | |
tree | f61da17f3072f61186e83aad0bf04021f6310a67 /jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src | |
parent | ea19df2de5865a0439be60465011f60e8cedd846 (diff) | |
download | webtools.dali-4e596fa171c6837f93b7271ba807c310464090dd.tar.gz webtools.dali-4e596fa171c6837f93b7271ba807c310464090dd.tar.xz webtools.dali-4e596fa171c6837f93b7271ba807c310464090dd.zip |
reworked test jar dependencies
Diffstat (limited to 'jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src')
8 files changed, 262 insertions, 22 deletions
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/JptJaxbEclipseLinkCoreTestsPlugin.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/JptJaxbEclipseLinkCoreTestsPlugin.java index 2d7824687e..0c35938df2 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/JptJaxbEclipseLinkCoreTestsPlugin.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/JptJaxbEclipseLinkCoreTestsPlugin.java @@ -25,22 +25,12 @@ public class JptJaxbEclipseLinkCoreTestsPlugin private static JptJaxbEclipseLinkCoreTestsPlugin INSTANCE; - public static final String ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.eclipselink.jar"; - public static JptJaxbEclipseLinkCoreTestsPlugin instance() { return INSTANCE; } - public static String eclipseLinkJarName() { - return getSystemProperty(ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY); - } - - private static String getSystemProperty(String propertyName) { - return System.getProperty(propertyName); - } - - + // ********** plug-in implementation ********** public JptJaxbEclipseLinkCoreTestsPlugin() { diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/ELJaxbCoreTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/ELJaxbCoreTests.java new file mode 100644 index 0000000000..f43b6463de --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/ELJaxbCoreTests.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jaxb.eclipselink.core.tests.internal; + +import java.io.File; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.eclipse.jpt.jaxb.core.tests.internal.projects.TestJaxbProject; +import org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.context.ELJaxbCoreContextModelTests; +import org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.resource.ELJaxbCoreResourceModelTests; + + +public class ELJaxbCoreTests { + + public static Test suite() { + TestSuite suite = new TestSuite(ELJaxbCoreTests.class.getPackage().getName()); + suite.addTest(ELJaxbCoreResourceModelTests.suite()); + suite.addTest(ELJaxbCoreContextModelTests.suite()); + return suite; + } + + public static boolean requiredJarsExists() { + return elJaxbJarPropertyExists() && elJaxbJarFileExists(); + } + + public static boolean elJaxbJarPropertyExists() { + return getSystemProperty(TestJaxbProject.EL_JAXB_JAR_NAME_SYSTEM_PROPERTY) != null; + } + + public static boolean elJaxbJarFileExists() { + return (new File(getSystemProperty(TestJaxbProject.EL_JAXB_JAR_NAME_SYSTEM_PROPERTY))).exists(); + } + + public static String buildMissingJarErrorMessage() { + if( ! elJaxbJarPropertyExists()) { + return errorMissingProperty(TestJaxbProject.EL_JAXB_JAR_NAME_SYSTEM_PROPERTY); + } + return errorJarFileDoesNotExist(getSystemProperty(TestJaxbProject.EL_JAXB_JAR_NAME_SYSTEM_PROPERTY)); + } + + /*********** private **********/ + private static String errorMissingProperty(String propertyName) { + return "missing Java system property: \"" + propertyName + "\""; + } + + private static String errorJarFileDoesNotExist(String propertyValue) { + return "JAR file doesn't exist: \"" + propertyValue + "\""; + } + + private static String getSystemProperty(String propertyName) { + return System.getProperty(propertyName); + } + + + private ELJaxbCoreTests() { + super(); + throw new UnsupportedOperationException(); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextModelTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextModelTestCase.java new file mode 100644 index 0000000000..4bb947c77f --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextModelTestCase.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jaxb.eclipselink.core.tests.internal.context; + +import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription; +import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; +import org.eclipse.jpt.jaxb.eclipselink.core.ELJaxbPlatform; + + +public abstract class ELJaxbContextModelTestCase + extends JaxbContextModelTestCase { + + public ELJaxbContextModelTestCase(String name) { + super(name); + } + + + @Override + protected JaxbPlatformDescription getPlatform() { + return ELJaxbPlatform.getDefaultPlatform(getProjectFacetVersion()); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbCoreContextModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbCoreContextModelTests.java new file mode 100644 index 0000000000..1eacaf9eb8 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbCoreContextModelTests.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jaxb.eclipselink.core.tests.internal.context; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.ELJaxbCoreTests; +import org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.context.java.ELJaxbCoreJavaContextModelTests; + + +public class ELJaxbCoreContextModelTests extends TestCase +{ + public static Test suite() { + TestSuite suite = new TestSuite(ELJaxbCoreContextModelTests.class.getName()); + + if (ELJaxbCoreTests.requiredJarsExists()) { +// suite.addTestSuite(GenericContextRootTests.class); + suite.addTest(ELJaxbCoreJavaContextModelTests.suite()); + } + else { + suite.addTest(TestSuite.warning(ELJaxbCoreTests.buildMissingJarErrorMessage())); + } + return suite; + } + + private ELJaxbCoreContextModelTests() { + super(); + throw new UnsupportedOperationException(); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/java/ELJavaXmlInverseReferenceMappingTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/java/ELJavaXmlInverseReferenceMappingTests.java new file mode 100644 index 0000000000..ba7710b517 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/java/ELJavaXmlInverseReferenceMappingTests.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jaxb.eclipselink.core.tests.internal.context.java; + +import java.util.Iterator; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.dom.MarkerAnnotation; +import org.eclipse.jdt.core.dom.NormalAnnotation; +import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; +import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; +import org.eclipse.jpt.common.core.utility.jdt.Member; +import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; +import org.eclipse.jpt.common.utility.internal.CollectionTools; +import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; +import org.eclipse.jpt.jaxb.core.context.JaxbClass; +import org.eclipse.jpt.jaxb.core.context.JaxbClassMapping; +import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; +import org.eclipse.jpt.jaxb.core.resource.java.JAXB; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.context.java.ELJavaXmlInverseReferenceMapping; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.ELJaxb; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.XmlInverseReferenceAnnotation; +import org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.context.ELJaxbContextModelTestCase; + + +public class ELJavaXmlInverseReferenceMappingTests + extends ELJaxbContextModelTestCase { + + public ELJavaXmlInverseReferenceMappingTests(String name) { + super(name); + } + + private ICompilationUnit createTypeWithXmlInverseReference() throws Exception { + return this.createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JAXB.XML_TYPE, ELJaxb.XML_INVERSE_REFERENCE); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@XmlType"); + } + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@XmlInverseReference"); + } + }); + } + + + public void testModifyMappedBy() throws Exception { + createTypeWithXmlInverseReference(); + + JaxbClass jaxbClass = (JaxbClass) CollectionTools.get(getContextRoot().getTypes(), 0); + JaxbClassMapping classMapping = jaxbClass.getMapping(); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(classMapping.getAttributes(), 0); + ELJavaXmlInverseReferenceMapping mapping = (ELJavaXmlInverseReferenceMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); + XmlInverseReferenceAnnotation annotation = (XmlInverseReferenceAnnotation) resourceAttribute.getAnnotation(ELJaxb.XML_INVERSE_REFERENCE); + + assertNull(annotation.getMappedBy()); + assertNull(mapping.getMappedBy()); + + mapping.setMappedBy("foo"); + + assertEquals("foo", annotation.getMappedBy()); + assertEquals("foo", mapping.getMappedBy()); + + mapping.setMappedBy(null); + + assertNull(annotation.getMappedBy()); + assertNull(mapping.getMappedBy()); + } + + public void testUpdateMappedBy() throws Exception { + createTypeWithXmlInverseReference(); + + JaxbClass jaxbClass = (JaxbClass) CollectionTools.get(getContextRoot().getTypes(), 0); + JaxbClassMapping classMapping = jaxbClass.getMapping(); + JaxbPersistentAttribute persistentAttribute = CollectionTools.get(classMapping.getAttributes(), 0); + ELJavaXmlInverseReferenceMapping mapping = (ELJavaXmlInverseReferenceMapping) persistentAttribute.getMapping(); + JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); + XmlInverseReferenceAnnotation annotation = (XmlInverseReferenceAnnotation) resourceAttribute.getAnnotation(ELJaxb.XML_INVERSE_REFERENCE); + + assertNull(annotation.getMappedBy()); + assertNull(mapping.getMappedBy()); + + AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + ELJavaXmlInverseReferenceMappingTests.this.addMemberValuePair( + (MarkerAnnotation) declaration.getAnnotationNamed(ELJaxb.XML_INVERSE_REFERENCE), + ELJaxb.XML_INVERSE_REFERENCE__MAPPED_BY, "foo"); + } + }); + + assertEquals("foo", annotation.getMappedBy()); + assertEquals("foo", mapping.getMappedBy()); + + annotatedElement.edit(new Member.Editor() { + public void edit(ModifiedDeclaration declaration) { + NormalAnnotation annotation = (NormalAnnotation) declaration.getAnnotationNamed(ELJaxb.XML_INVERSE_REFERENCE); + ELJavaXmlInverseReferenceMappingTests.this.values(annotation).remove(0); + } + }); + + assertNull(annotation.getMappedBy()); + assertNull(mapping.getMappedBy()); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/JaxbEclipseLinkCoreTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/java/ELJaxbCoreJavaContextModelTests.java index 403948f9b6..2d229f7797 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/JaxbEclipseLinkCoreTests.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/java/ELJaxbCoreJavaContextModelTests.java @@ -7,23 +7,24 @@ * Contributors: * Oracle - initial API and implementation *******************************************************************************/ -package org.eclipse.jpt.jaxb.eclipselink.core.tests.internal; +package org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.context.java; import junit.framework.Test; +import junit.framework.TestCase; import junit.framework.TestSuite; -import org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.resource.JaxbEclipseLinkCoreResourceModelTests; -public class JaxbEclipseLinkCoreTests { +public class ELJaxbCoreJavaContextModelTests + extends TestCase { public static Test suite() { - TestSuite suite = new TestSuite(JaxbEclipseLinkCoreTests.class.getPackage().getName()); - suite.addTest(JaxbEclipseLinkCoreResourceModelTests.suite()); + TestSuite suite = new TestSuite(ELJaxbCoreJavaContextModelTests.class.getName()); + suite.addTestSuite(ELJavaXmlInverseReferenceMappingTests.class); return suite; } - private JaxbEclipseLinkCoreTests() { + private ELJaxbCoreJavaContextModelTests() { super(); throw new UnsupportedOperationException(); } diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/JaxbEclipseLinkCoreResourceModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/ELJaxbCoreResourceModelTests.java index 09d8199946..11842ba139 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/JaxbEclipseLinkCoreResourceModelTests.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/ELJaxbCoreResourceModelTests.java @@ -15,18 +15,18 @@ import junit.framework.TestSuite; import org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.resource.java.ELJaxbJavaResourceModelTests; -public class JaxbEclipseLinkCoreResourceModelTests +public class ELJaxbCoreResourceModelTests extends TestCase { public static Test suite() { - TestSuite suite = new TestSuite(JaxbEclipseLinkCoreResourceModelTests.class.getName()); + TestSuite suite = new TestSuite(ELJaxbCoreResourceModelTests.class.getName()); suite.addTest(ELJaxbJavaResourceModelTests.suite()); return suite; } - private JaxbEclipseLinkCoreResourceModelTests() { + private ELJaxbCoreResourceModelTests() { super(); throw new UnsupportedOperationException(); } diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTestCase.java index 2ab7e242b7..fd80fff0a0 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTestCase.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTestCase.java @@ -12,8 +12,8 @@ package org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.resource.java; import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition; import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition; import org.eclipse.jpt.common.core.tests.internal.resource.java.JavaResourceModelTestCase; +import org.eclipse.jpt.jaxb.core.tests.internal.projects.TestJaxbProject; import org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_1.ELJaxb_2_1_PlatformDefinition; -import org.eclipse.jpt.jaxb.eclipselink.core.tests.JptJaxbEclipseLinkCoreTestsPlugin; public class ELJaxbJavaResourceModelTestCase @@ -27,7 +27,7 @@ public class ELJaxbJavaResourceModelTestCase @Override protected void setUp() throws Exception { super.setUp(); - this.javaProject.addJar(JptJaxbEclipseLinkCoreTestsPlugin.eclipseLinkJarName()); + this.javaProject.addJar(TestJaxbProject.elJaxbJarName()); } @Override |