diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse')
41 files changed, 0 insertions, 8277 deletions
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java deleted file mode 100644 index 75f078286c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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; - -import java.io.File; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.eclipselink.core.tests.internal.caching.JptEclipseLinkCoreCachingTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.connection.JptEclipseLinkCoreConnectionTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.JptEclipseLinkCoreContextModelTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.customization.JptEclipseLinkCoreCustomizationTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.logging.JptEclipseLinkCoreLoggingTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.options.JptEclipseLinkCoreOptionsTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.resource.JptEclipselinkCoreResourceModelTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.schema.generation.JptEclipseLinkCoreSchemaGenerationTests; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkCoreTests -{ - private static final String JPA_JAR_PROPERTY = TestJpaProject.JAR_NAME_SYSTEM_PROPERTY; - - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreTests.class.getPackage().getName()); - - if(jpaJarPropertyExists() && jpaJarFileExists()) { - suite.addTest(JptEclipseLinkCoreConnectionTests.suite()); - suite.addTest(JptEclipseLinkCoreOptionsTests.suite()); - suite.addTest(JptEclipseLinkCoreLoggingTests.suite()); - suite.addTest(JptEclipseLinkCoreCustomizationTests.suite()); - suite.addTest(JptEclipseLinkCoreCachingTests.suite()); - suite.addTest(JptEclipseLinkCoreSchemaGenerationTests.suite()); - suite.addTest(JptEclipselinkCoreResourceModelTests.suite()); - suite.addTest(JptEclipseLinkCoreContextModelTests.suite()); - } - else { - String message = ( ! jpaJarPropertyExists()) ? - "missing Java system property: \"" + JPA_JAR_PROPERTY + "\"" : - "missing JPA jar file: \"" + getJpaJarProperty() + "\""; - suite.addTest(TestSuite.warning(message)); - } - return suite; - } - - public static boolean jpaJarPropertyExists() { - String jpaJarName = getJpaJarProperty(); - return jpaJarName != null; - } - - public static boolean jpaJarFileExists() { - File file = new File(getJpaJarProperty()); - return file.exists(); - } - - public static String getJpaJarProperty() { - return System.getProperty(JPA_JAR_PROPERTY); - } - - private JptEclipseLinkCoreTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/PersistenceUnitTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/PersistenceUnitTestCase.java deleted file mode 100644 index 202132b34f..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/PersistenceUnitTestCase.java +++ /dev/null @@ -1,427 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkPersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; - -/** - * PersistenceUnitTestCase - */ -public abstract class PersistenceUnitTestCase extends ContextModelTestCase -{ - protected PersistenceUnit subject; - - protected PropertyValueModel<PersistenceUnit> subjectHolder; - - protected EclipseLinkProperties persistenceUnitProperties; - - protected PropertyChangeEvent propertyChangedEvent; - - protected int propertyChangedEventCount; - - protected int propertiesTotal; - - protected int modelPropertiesSizeOriginal; - - protected int modelPropertiesSize; - - protected PersistenceUnitTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject = this.persistenceUnit(); - this.subjectHolder = new SimplePropertyValueModel<PersistenceUnit>(this.subject); - this.persistenceUnitProperties = new EclipseLinkJpaProperties(this.subject); - this.populatePu(); - } - - // ****** abstract methods ******* - protected abstract PersistenceUnitProperties model(); - - /** - * Initializes directly the PU properties before testing. Cannot use - * Property Holder to initialize because it is not created yet - */ - protected abstract void populatePu(); - - /** - * Gets the model's property identified by the given propertyName. - * - * @param propertyName - * name of property to get - * @throws Exception - */ - protected abstract Object getProperty(String propertyName) throws Exception; - - - /** - * Sets the model's property identified by the given propertyName. - * Used in verifySetProperty() - * - * @param propertyName - * name of property to be set - * @param newValue - * value of property - * @throws Exception - */ - protected abstract void setProperty(String propertyName, Object newValue) throws Exception; - - - // ****** convenience test methods ******* - - protected String getEclipseLinkStringValueOf(Object value) { - return EclipseLinkPersistenceUnitProperties.getEclipseLinkStringValueOf(value); - } - - /** - * Put into persistenceUnit properties. Do not allows to put duplicate entry. - * - * @param key - - * EclipseLink Key - * @param value - - * property value - */ - protected void persistenceUnitPut(String key, Object value) { - - this.persistenceUnitPut( key, value, false); - } - - protected void persistenceUnitPut(String key, Object value, boolean allowDuplicates) { - if (key == null) { - throw new IllegalArgumentException("EclipseLink Key cannot be null"); - } - if (value == null) - this.putNullProperty(key); - else - this.putProperty_(key, value, allowDuplicates); - } - - private void putProperty_(String elKey, Object value, boolean allowDuplicates) { - this.clearEvent(); - this.persistenceUnit().putProperty(elKey, this.getEclipseLinkStringValueOf(value), allowDuplicates); - } - - protected void putNullProperty(String elKey) { - this.clearEvent(); - this.persistenceUnit().putProperty(elKey, null, false); - } - - protected void clearEvent() { - this.propertyChangedEvent = null; - this.propertyChangedEventCount = 0; - } - - protected void throwMissingDefinition(String methodName, String propertyName) throws NoSuchFieldException { - throw new NoSuchFieldException("Missing Definition for: " + methodName + "( " + propertyName + ")"); - } - - protected void throwUnsupportedOperationException(ListChangeEvent e) { - throw new UnsupportedOperationException(e.getAspectName()); - } - - protected PropertyChangeListener buildPropertyChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - PersistenceUnitTestCase.this.propertyChangedEvent = event; - PersistenceUnitTestCase.this.propertyChangedEventCount++; - } - - @Override - public String toString() { - return "PersistenceUnit listener"; - } - }; - } - - // ****** verify EclipseLink properties ******* - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifyAAValue(Boolean expectedValue, Boolean subjectValue, PropertyValueModel<Boolean> aa, String persistenceXmlKey) { - assertEquals(expectedValue, subjectValue); - assertEquals(expectedValue, aa.getValue()); - if (expectedValue != null) { - assertEquals(expectedValue.toString(), this.persistenceUnit().getProperty(persistenceXmlKey).getValue()); - } - } - - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected <T extends Enum<T>> void verifyAAValue(T expectedValue, T subjectValue, PropertyValueModel<? extends Enum<T>> aa, String elKey) { - assertEquals(expectedValue, subjectValue); - assertEquals(expectedValue, aa.getValue()); - if (expectedValue != null) { - assertEquals(this.getEclipseLinkStringValueOf(expectedValue), this.persistenceUnit().getProperty(elKey).getValue()); - } - } - - /** - * Performs the following tests:<br> - * 1. verify total number of EclipseLink properties<br> - * 2. verify PU has the given propertyName<br> - * 3. verify listening to propertyListAdapter<br> - * 4. verify that the model can identify propertyName<br> - */ - protected void verifyInitialState(String propertyName, String elKey, ListValueModel<Property> propertyListAdapter) throws Exception { - assertEquals("Total not updated in populatePu(): ", propertyListAdapter.size(), this.propertiesTotal); - this.verifyPuHasProperty(elKey, "Property not added to populatePu()"); - this.verifyHasListeners(propertyListAdapter); - this.verifyHasListeners(this.model(), propertyName); - - Property property = this.persistenceUnit().getProperty(elKey); - assertTrue("model.itemIsProperty() is false: ", model().itemIsProperty(property)); - assertEquals("propertyIdFor() not updated: ", propertyName, model().propertyIdFor(property)); - } - - /** - * Verifies that the persistence unit is populated, and that the model for - * the tested Property is initialized with the value from the persistence - * unit. - * @throws Exception - */ - protected void verifyModelInitialized(String elKey, Object expectedValue) throws Exception { - Property property = this.persistenceUnit().getProperty(elKey); - assertTrue("model.itemIsProperty() is false: ", model().itemIsProperty(property)); - - assertEquals("PersistenceUnit not populated - populatedPu()", this.getEclipseLinkStringValueOf(expectedValue), property.getValue()); - String propertyName = this.model().propertyIdFor(property); - Object modelValue = this.getProperty(propertyName); - assertEquals( - "Model not initialized - model.initializeProperties() - modelValue = " + modelValue, - expectedValue, - modelValue); - } - - /** - * Performs the following operations with the property:<br> - * 1. verifies the initial state<br> - * 2. persistenceUnit putProperty<br> - * 3. adapter setProperty<br> - */ - protected void verifySetProperty(String elKey, Object testValue1, Object testValue2) throws Exception { - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - Property property = this.persistenceUnit().getProperty(elKey); - String propertyName = this.model().propertyIdFor(property); - - // Basic - this.verifyInitialState(propertyName, elKey, propertyListAdapter); - - // Replace - this.persistenceUnitPut(elKey, testValue2); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutProperty(propertyName, testValue2); - - // Replace by setting model object - this.clearEvent(); - this.setProperty(propertyName, testValue1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutProperty(propertyName, testValue1); - } - - /** - * Performs the following operations with the property:<br> - * 1. performs a remove on the PU<br> - * 2. performs a add with putProperty<br> - * 3. performs a replace with putProperty<br> - */ - protected void verifyAddRemoveProperty(String elKey, Object testValue1, Object testValue2) throws Exception { - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - Property property = this.persistenceUnit().getProperty(elKey); - String propertyName = this.model().propertyIdFor(property); - - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - assertTrue("persistenceUnit.properties doesn't contains: " + elKey, this.persistenceUnit().containsProperty(elKey)); - this.persistenceUnit().removeProperty(elKey); - assertFalse(this.persistenceUnit().containsProperty(elKey)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutProperty(propertyName, null); - - // Add original CacheTypeDefault - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitPut(elKey, testValue1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutProperty(propertyName, testValue1); - - // Replace - this.persistenceUnitPut(elKey, testValue2); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutProperty(propertyName, testValue2); - } - - /** - * Verifies the model's property identified by the given propertyName - * Used in verifySetProperty() and verifyAddRemoveProperty - * - * @param propertyName - * name of property to be verified - * @param expectedValue - * @throws Exception - */ - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - - this.verifyPutEvent(propertyName, this.getProperty(propertyName), expectedValue); - } - - /** - * Verifies the event of the put() action. - * - * @param propertyName - * name of property to be verified - * @param propertyValue - * value of property - * @param expectedValue - * @throws Exception - */ - protected void verifyPutEvent(String propertyName, Object propertyValue, Object expectedValue) { - - this.verifyEvent(propertyName); - this.verifyEventValue(propertyValue, expectedValue); - } - - /** - * Performs the following tests:<br> - * 1. verifies the new value of this.propertyChangedEvent<br> - * 2. verifies the given value<br> - */ - protected void verifyEventValue(Object value, Object expectedValue) { - // verify event value - assertEquals(expectedValue, this.propertyChangedEvent.getNewValue()); - assertEquals(expectedValue, value); - } - - /** - * Performs the following tests:<br> - * 1. verifies that an event is fired<br> - * 2. verifies that it is the correct event<br> - * 3. verifies that a single event is fired<br> - */ - protected void verifyEvent(String propertyName) { - // verify event received - assertNotNull("No Event Fired.", this.propertyChangedEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.propertyChangedEvent.getAspectName(), propertyName); - // verify event occurence - assertTrue("No Event Received.", this.propertyChangedEventCount > 0); - assertTrue("Multiple Event Received (" + this.propertyChangedEventCount + ")", - this.propertyChangedEventCount < 2); - } - - protected void verifyHasNoListeners(ListValueModel listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES)); - } - - protected void verifyHasListeners(ListValueModel listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - protected void verifyHasListeners(PersistenceUnitProperties model, String propertyName) throws Exception { - assertTrue("Listener not added in setUp() - " + propertyName, ((AbstractModel) model).hasAnyPropertyChangeListeners(propertyName)); - } - - protected void verifyHasListeners(PropertyValueModel pvm, String propertyName) throws Exception { - assertTrue(((AbstractModel) pvm).hasAnyPropertyChangeListeners(propertyName)); - } - - protected void verifyPuHasProperty(String eclipseLinkPropertyName, String msg) { - assertNotNull(msg + " - " + eclipseLinkPropertyName, this.persistenceUnit().getProperty(eclipseLinkPropertyName)); - } - - protected void verifyPuHasNotProperty(String eclipseLinkPropertyName, String msg) { - assertNull(msg + " - " + eclipseLinkPropertyName, this.persistenceUnit().getProperty(eclipseLinkPropertyName)); - } - - // ****** verify Persistence Unit properties ******* - - /** - * Performs the following tests:<br> - * 1. verify Persistence Unit specified property initialized<br> - * 2. set the PU property and verify PU its value<br> - * 3. set the PU property to null and verify PU its value<br> - * 4. set model value property and verify PU modified<br> - * 5. set model value property to null and verify PU modified<br> - */ - protected void verifySetPersistenceUnitProperty(String propertyName, Object testValue1, Object testValue2) throws Exception { - // Basic - this.verifyHasListeners(this.model(), propertyName); - assertEquals("Persistence Unit not initialized.", testValue1, this.getPersistenceUnitProperty(propertyName)); - Object initialModelValue = this.getProperty(propertyName); - assertEquals( - "Model not initialized - model.initializeProperties() - modelValue = " + initialModelValue, - testValue1, - initialModelValue); - - // Modifying value by setting PU - this.clearEvent(); - this.setPersistenceUnitProperty(propertyName, testValue2); - this.verifyModelModified(propertyName, testValue2); - - // Setting PU to null - this.clearEvent(); - this.setPersistenceUnitProperty(propertyName, null); - this.verifyModelModified(propertyName, null); - - // Modifying value by setting model object - this.clearEvent(); - this.setProperty(propertyName, testValue1); - this.verifyPersistenceUnitModified(propertyName, testValue1); - - // Setting model to null - this.clearEvent(); - this.setProperty(propertyName, null); - this.verifyPersistenceUnitModified(propertyName, null); - } - - protected void verifyPersistenceUnitModified(String propertyName, Object expectedValue) throws Exception { - assertEquals("Persistence Unit not modified.", expectedValue, this.getPersistenceUnitProperty(propertyName)); - this.verifyPutProperty(propertyName, expectedValue); - } - - protected void verifyModelModified(String propertyName, Object expectedValue) throws Exception { - Object modelValue = this.getProperty(propertyName); - assertEquals("connection value not modified.", expectedValue, modelValue); - this.verifyPutEvent(propertyName, modelValue, expectedValue); - } - - protected void setPersistenceUnitProperty(String propertyName, Object newValue) throws NoSuchFieldException { - throw new NoSuchMethodError("Missing implementation for setPersistenceUnitProperty"); - } - - protected Object getPersistenceUnitProperty(String propertyName) throws NoSuchFieldException { - throw new NoSuchMethodError("Missing implementation for getPersistenceUnitProperty"); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java deleted file mode 100644 index 9e53dd42e4..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java +++ /dev/null @@ -1,436 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.caching; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.context.persistence.GenericProperty; -import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener; -import org.eclipse.jpt.eclipselink.core.internal.context.caching.CacheProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.caching.CacheType; -import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; -import org.eclipse.jpt.eclipselink.core.internal.context.caching.EclipseLinkCaching; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * Tests the update of model objects by the Caching adapter when the - * PersistenceUnit changes. - */ -public class CachingAdapterTests extends PersistenceUnitTestCase -{ - private Caching caching; - private ListChangeEvent entitiesEvent; - - public static final String ENTITY_TEST = "Employee"; - public static final String ENTITY_TEST_2 = "Address"; - - public static final String CACHE_TYPE_DEFAULT_KEY = Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT; - public static final CacheType CACHE_TYPE_DEFAULT_TEST_VALUE = CacheType.soft_weak; - public static final CacheType CACHE_TYPE_DEFAULT_TEST_VALUE_2 = CacheType.full; - - public static final String CACHE_SIZE_DEFAULT_KEY = Caching.ECLIPSELINK_CACHE_SIZE_DEFAULT; - public static final Integer CACHE_SIZE_DEFAULT_TEST_VALUE = 12345; - public static final Integer CACHE_SIZE_DEFAULT_TEST_VALUE_2 = 67890; - - public static final String SHARED_CACHE_DEFAULT_KEY = Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT; - public static final Boolean SHARED_CACHE_DEFAULT_TEST_VALUE = false; - public static final Boolean SHARED_CACHE_DEFAULT_TEST_VALUE_2 = true; - - public static final String CACHE_TYPE_KEY = Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_TEST; - public static final CacheType CACHE_TYPE_TEST_VALUE = CacheType.soft_weak; - public static final CacheType CACHE_TYPE_TEST_VALUE_2 = CacheType.full; - - public static final String SHARED_CACHE_KEY = Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_TEST; - public static final Boolean SHARED_CACHE_TEST_VALUE = false; - public static final Boolean SHARED_CACHE_TEST_VALUE_2 = true; - - public static final String CACHE_SIZE_KEY = Caching.ECLIPSELINK_CACHE_SIZE + ENTITY_TEST; - public static final Integer CACHE_SIZE_TEST_VALUE = 12345; - public static final Integer CACHE_SIZE_TEST_VALUE_2 = 67890; - - public CachingAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.caching = this.persistenceUnitProperties.getCaching(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.caching.addPropertyChangeListener(Caching.CACHE_TYPE_DEFAULT_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Caching.CACHE_SIZE_DEFAULT_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Caching.SHARED_CACHE_DEFAULT_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Caching.CACHE_TYPE_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Caching.CACHE_SIZE_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Caching.SHARED_CACHE_PROPERTY, propertyChangeListener); - - ListChangeListener entitiesChangeListener = this.buildEntitiesChangeListener(); - this.caching.addListChangeListener(Caching.ENTITIES_LIST_PROPERTY, entitiesChangeListener); - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 6; - this.propertiesTotal = this.modelPropertiesSizeOriginal + 4; // 4 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitPut("misc.property.1", "value.1"); - this.persistenceUnitPut(CACHE_TYPE_DEFAULT_KEY, CACHE_TYPE_DEFAULT_TEST_VALUE); - this.persistenceUnitPut("misc.property.2", "value.2"); - this.persistenceUnitPut(CACHE_SIZE_DEFAULT_KEY, CACHE_SIZE_DEFAULT_TEST_VALUE); - this.persistenceUnitPut(SHARED_CACHE_DEFAULT_KEY, SHARED_CACHE_DEFAULT_TEST_VALUE); - this.persistenceUnitPut("misc.property.3", "value.3"); - this.persistenceUnitPut("misc.property.4", "value.4"); - this.persistenceUnitPut(CACHE_SIZE_KEY, CACHE_SIZE_TEST_VALUE); - this.persistenceUnitPut(CACHE_TYPE_KEY, CACHE_TYPE_TEST_VALUE); - this.persistenceUnitPut(SHARED_CACHE_KEY, SHARED_CACHE_TEST_VALUE); - return; - } - - // ********** Listeners ********** - private ListChangeListener buildEntitiesChangeListener() { - return new ListChangeListener() { - public void itemsAdded(ListChangeEvent e) { - CachingAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsRemoved(ListChangeEvent e) { - CachingAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsReplaced(ListChangeEvent e) { - CachingAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsMoved(ListChangeEvent e) { - CachingAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void listCleared(ListChangeEvent e) { - CachingAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void listChanged(ListChangeEvent e) { - CachingAdapterTests.this.entityChanged(e); - } - }; - } - - @Override - protected void clearEvent() { - super.clearEvent(); - this.entitiesEvent = null; - } - - void entityChanged(ListChangeEvent e) { - this.entitiesEvent = e; - } - - // ********** entities list ********** - public void testEntitiesList() throws Exception { - // add - this.clearEvent(); - this.caching.addEntity(ENTITY_TEST_2); - - // verify event received - assertNotNull("No Event Fired.", this.entitiesEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.entitiesEvent.getAspectName(), Caching.ENTITIES_LIST_PROPERTY); - - // remove - this.clearEvent(); - this.caching.removeEntity(ENTITY_TEST_2); - // verify event received - assertNotNull("No Event Fired.", this.entitiesEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.entitiesEvent.getAspectName(), Caching.ENTITIES_LIST_PROPERTY); - } - - // ********** Listeners tests ********** - public void testHasListeners() throws Exception { - // new - ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter = - (ListAspectAdapter<PersistenceUnit, Property>) ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertiesAdapter(); - GenericProperty ctdProperty = (GenericProperty) this.persistenceUnit().getProperty(CACHE_TYPE_DEFAULT_KEY); - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(ctdProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - this.verifyHasListeners(this.caching, Caching.CACHE_TYPE_DEFAULT_PROPERTY); - this.verifyHasListeners(propertyListAdapter); - - EclipseLinkCaching elCaching = (EclipseLinkCaching) this.caching; - PersistenceUnitPropertyListListener propertyListListener = elCaching.propertyListListener(); - propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener); - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); // other properties are still listening - this.verifyHasListeners(this.caching, Caching.CACHE_TYPE_DEFAULT_PROPERTY); - } - - // ********** CacheTypeDefault ********** - /** - * Tests the update of CacheTypeDefault property by the Caching adapter when - * the PU or the model changes. - */ - public void testSetCacheTypeDefault() throws Exception { - this.verifyModelInitialized( - CACHE_TYPE_DEFAULT_KEY, - CACHE_TYPE_DEFAULT_TEST_VALUE); - this.verifySetProperty( - CACHE_TYPE_DEFAULT_KEY, - CACHE_TYPE_DEFAULT_TEST_VALUE, - CACHE_TYPE_DEFAULT_TEST_VALUE_2); - } - - public void testAddRemoveCacheTypeDefault() throws Exception { - this.verifyAddRemoveProperty( - CACHE_TYPE_DEFAULT_KEY, - CACHE_TYPE_DEFAULT_TEST_VALUE, - CACHE_TYPE_DEFAULT_TEST_VALUE_2); - } - - // ********** CacheSizeDefault ********** - /** - * Tests the update of CacheSizeDefault property by the Caching adapter when - * the PU or the model changes. - */ - public void testSetCacheSizeDefault() throws Exception { - this.verifyModelInitialized( - CACHE_SIZE_DEFAULT_KEY, - CACHE_SIZE_DEFAULT_TEST_VALUE); - this.verifySetProperty( - CACHE_SIZE_DEFAULT_KEY, - CACHE_SIZE_DEFAULT_TEST_VALUE, - CACHE_SIZE_DEFAULT_TEST_VALUE_2); - } - - public void testAddRemoveCacheSizeDefault() throws Exception { - this.verifyAddRemoveProperty( - CACHE_SIZE_DEFAULT_KEY, - CACHE_SIZE_DEFAULT_TEST_VALUE, - CACHE_SIZE_DEFAULT_TEST_VALUE_2); - } - - // ********** SharedCacheDefault ********** - public void testSetSharedCacheDefault() throws Exception { - this.verifyModelInitialized( - SHARED_CACHE_DEFAULT_KEY, - SHARED_CACHE_DEFAULT_TEST_VALUE); - this.verifySetProperty( - SHARED_CACHE_DEFAULT_KEY, - SHARED_CACHE_DEFAULT_TEST_VALUE, - SHARED_CACHE_DEFAULT_TEST_VALUE_2); - } - - public void testAddRemoveSharedCacheDefault() throws Exception { - this.verifyAddRemoveProperty( - SHARED_CACHE_DEFAULT_KEY, - SHARED_CACHE_DEFAULT_TEST_VALUE, - SHARED_CACHE_DEFAULT_TEST_VALUE_2); - } - - // ********** CacheType ********** - /** - * Tests the update of CacheType property by the Caching adapter when the PU - * or the model changes. - */ - public void testSetCacheType() throws Exception { - this.verifyModelInitialized( - CACHE_TYPE_KEY, - CACHE_TYPE_TEST_VALUE); - this.verifySetCachingProperty( - Caching.CACHE_TYPE_PROPERTY, - CACHE_TYPE_KEY, - CACHE_TYPE_TEST_VALUE, - CACHE_TYPE_TEST_VALUE_2); - } - - public void testAddRemoveCacheType() throws Exception { - this.verifyAddRemoveCachingProperty( - Caching.CACHE_TYPE_PROPERTY, - CACHE_TYPE_KEY, - CACHE_TYPE_TEST_VALUE, - CACHE_TYPE_TEST_VALUE_2); - } - - // ********** CacheSize ********** - /** - * Tests the update of CacheSize property by the Caching adapter when the PU - * or the model changes. - */ - public void testSetCacheSize() throws Exception { - this.verifyModelInitialized( - CACHE_SIZE_KEY, - CACHE_SIZE_TEST_VALUE); - this.verifySetCachingProperty( - Caching.CACHE_SIZE_PROPERTY, - CACHE_SIZE_KEY, - CACHE_SIZE_TEST_VALUE, - CACHE_SIZE_TEST_VALUE_2); - } - - public void testAddRemoveCacheSize() throws Exception { - this.verifyAddRemoveCachingProperty( - Caching.CACHE_SIZE_PROPERTY, - CACHE_SIZE_KEY, - CACHE_SIZE_TEST_VALUE, - CACHE_SIZE_TEST_VALUE_2); - } - - // ********** SharedCache ********** - /** - * Tests the update of SharedCache property by the Caching adapter when the - * PU or the model changes. - */ - public void testSetSharedCache() throws Exception { - this.verifyModelInitialized( - SHARED_CACHE_KEY, - SHARED_CACHE_TEST_VALUE); - this.verifySetCachingProperty( - Caching.SHARED_CACHE_PROPERTY, - SHARED_CACHE_KEY, - SHARED_CACHE_TEST_VALUE, - SHARED_CACHE_TEST_VALUE_2); - } - - public void testAddRemoveSharedCache() throws Exception { - this.verifyAddRemoveCachingProperty( - Caching.SHARED_CACHE_PROPERTY, - SHARED_CACHE_KEY, - SHARED_CACHE_TEST_VALUE, - SHARED_CACHE_TEST_VALUE_2); - } - - // ****** convenience methods ******* - protected PersistenceUnitProperties model() { - return this.caching; - } - - protected void verifySetCachingProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - // Basic - this.verifyInitialState(propertyName, key, propertyListAdapter); - - // Replace - this.persistenceUnitPut(key, testValue2); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue2); - - // Replace by setting model object - this.clearEvent(); - this.setCachingProperty(propertyName, ENTITY_TEST, testValue1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue1); - } - - protected void verifyAddRemoveCachingProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.persistenceUnit().removeProperty(key); - assertFalse(this.persistenceUnit().containsProperty(key)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, null); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - - // Add original Property - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitPut(key, testValue1); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - - // Replace - this.persistenceUnitPut(key, testValue2); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue2); - } - - protected void verifyPutCachingProperty(String propertyName, String entityName, Object expectedValue) throws Exception { - this.verifyEvent(propertyName); - this.verifyCachingEvent(propertyName, entityName, expectedValue); - } - - protected void verifyCachingEvent(String propertyName, String entityName, Object expectedValue) throws Exception { - // verify event value - CacheProperties cache = (CacheProperties) this.propertyChangedEvent.getNewValue(); - if (propertyName.equals(Caching.CACHE_TYPE_PROPERTY)) { - assertEquals(expectedValue, cache.getType()); - assertEquals(expectedValue, this.caching.getCacheType(entityName)); - } - else if (propertyName.equals(Caching.CACHE_SIZE_PROPERTY)) { - assertEquals(expectedValue, cache.getSize()); - assertEquals(expectedValue, this.caching.getCacheSize(entityName)); - } - else if (propertyName.equals(Caching.SHARED_CACHE_PROPERTY)) { - assertEquals(expectedValue, cache.isShared()); - assertEquals(expectedValue, this.caching.getSharedCache(entityName)); - } - else { - this.throwMissingDefinition("verifyCachingEvent", propertyName); - } - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Caching.CACHE_TYPE_DEFAULT_PROPERTY)) - this.caching.setCacheTypeDefault((CacheType) newValue); - else if (propertyName.equals(Caching.CACHE_SIZE_DEFAULT_PROPERTY)) - this.caching.setCacheSizeDefault((Integer) newValue); - else if (propertyName.equals(Caching.SHARED_CACHE_DEFAULT_PROPERTY)) - this.caching.setSharedCacheDefault((Boolean) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - protected void setCachingProperty(String propertyName, String entityName, Object newValue) throws NoSuchFieldException { - if (propertyName.equals(Caching.CACHE_TYPE_PROPERTY)) - this.caching.setCacheType((CacheType) newValue, entityName); - else if (propertyName.equals(Caching.CACHE_SIZE_PROPERTY)) - this.caching.setCacheSize((Integer) newValue, entityName); - else if (propertyName.equals(Caching.SHARED_CACHE_PROPERTY)) - this.caching.setSharedCache((Boolean) newValue, entityName); - else - this.throwMissingDefinition("setCachingProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Caching.CACHE_TYPE_DEFAULT_PROPERTY)) - modelValue = this.caching.getCacheTypeDefault(); - else if (propertyName.equals(Caching.CACHE_SIZE_DEFAULT_PROPERTY)) - modelValue = this.caching.getCacheSizeDefault(); - else if (propertyName.equals(Caching.SHARED_CACHE_DEFAULT_PROPERTY)) - modelValue = this.caching.getSharedCacheDefault(); - else if (propertyName.equals(Caching.CACHE_SIZE_PROPERTY)) - modelValue = this.caching.getCacheSize(ENTITY_TEST); - else if (propertyName.equals(Caching.CACHE_TYPE_PROPERTY)) - modelValue = this.caching.getCacheType(ENTITY_TEST); - else if (propertyName.equals(Caching.SHARED_CACHE_PROPERTY)) - modelValue = this.caching.getSharedCache(ENTITY_TEST); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingValueModelTests.java deleted file mode 100644 index 24f7d7a80e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingValueModelTests.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.caching; - -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.caching.CacheType; -import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * CachingValueModelTests - */ -public class CachingValueModelTests extends PersistenceUnitTestCase -{ - private Caching caching; - private PropertyValueModel<Caching> cachingHolder; - - private WritablePropertyValueModel<CacheType> cacheTypeHolder; - private PropertyChangeListener cacheTypeListener; - private PropertyChangeEvent cacheTypeEvent; - - private WritablePropertyValueModel<Boolean> sharedCacheHolder; - private PropertyChangeListener sharedCacheListener; - private PropertyChangeEvent sharedCacheEvent; - - private WritablePropertyValueModel<CacheType> cacheTypeDefaultHolder; - private PropertyChangeListener cacheTypeDefaultListener; - private PropertyChangeEvent cacheTypeDefaultEvent; - - private WritablePropertyValueModel<Boolean> sharedCacheDefaultHolder; - private PropertyChangeListener sharedCacheDefaultListener; - private PropertyChangeEvent sharedCacheDefaultEvent; - - public static final String ENTITY_NAME_TEST_VALUE = "Employee"; - public static final CacheType CACHE_TYPE_TEST_VALUE = CacheType.hard_weak; - public static final Boolean SHARED_CACHE_TEST_VALUE = Boolean.FALSE; - public static final CacheType CACHE_TYPE_DEFAULT_TEST_VALUE = CacheType.weak; - public static final Boolean SHARED_CACHE_DEFAULT_TEST_VALUE = Boolean.FALSE; - - public CachingValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.caching = this.persistenceUnitProperties.getCaching(); // Subject - this.cachingHolder = new SimplePropertyValueModel<Caching>(this.caching); - - this.cacheTypeHolder = this.buildCacheTypeAA(this.cachingHolder); - this.cacheTypeListener = this.buildCacheTypeChangeListener(); - this.cacheTypeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeListener); - this.cacheTypeEvent = null; - - this.sharedCacheHolder = this.buildSharedCacheAA(this.cachingHolder); - this.sharedCacheListener = this.buildSharedCacheChangeListener(); - this.sharedCacheHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheListener); - this.sharedCacheEvent = null; - - this.cacheTypeDefaultHolder = this.buildCacheTypeDefaultAA(this.cachingHolder); - this.cacheTypeDefaultListener = this.buildCacheTypeDefaultChangeListener(); - this.cacheTypeDefaultHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeDefaultListener); - this.cacheTypeDefaultEvent = null; - - this.sharedCacheDefaultHolder = this.buildSharedCacheDefaultAA(this.cachingHolder); - this.sharedCacheDefaultListener = this.buildSharedCacheDefaultChangeListener(); - this.sharedCacheDefaultHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheDefaultListener); - this.sharedCacheDefaultEvent = null; - } - - public void testHasListeners() { - AbstractModel subjectCaching = (AbstractModel) this.caching; // Subject - PropertyAspectAdapter<Caching, CacheType> cacheTypeAA = - (PropertyAspectAdapter<Caching, CacheType>) this.cacheTypeHolder; - assertTrue(cacheTypeAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(subjectCaching.hasAnyPropertyChangeListeners(Caching.CACHE_TYPE_PROPERTY)); - - cacheTypeAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeListener); - assertFalse(subjectCaching.hasAnyPropertyChangeListeners(Caching.CACHE_TYPE_PROPERTY)); - assertFalse(cacheTypeAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - PropertyAspectAdapter<Caching, Boolean> sharedCacheAA = - (PropertyAspectAdapter<Caching, Boolean>) this.sharedCacheHolder; - assertTrue(sharedCacheAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(subjectCaching.hasAnyPropertyChangeListeners(Caching.SHARED_CACHE_PROPERTY)); - - sharedCacheAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheListener); - assertFalse(subjectCaching.hasAnyPropertyChangeListeners(Caching.SHARED_CACHE_PROPERTY)); - assertFalse(sharedCacheAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - PropertyAspectAdapter<Caching, CacheType> cacheTypeDefaultAA = - (PropertyAspectAdapter<Caching, CacheType>) this.cacheTypeDefaultHolder; - assertTrue(cacheTypeDefaultAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(subjectCaching.hasAnyPropertyChangeListeners(Caching.CACHE_TYPE_DEFAULT_PROPERTY)); - - cacheTypeDefaultAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeDefaultListener); - assertFalse(subjectCaching.hasAnyPropertyChangeListeners(Caching.CACHE_TYPE_DEFAULT_PROPERTY)); - assertFalse(cacheTypeDefaultAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - PropertyAspectAdapter<Caching, Boolean> sharedCacheDefaultAA = - (PropertyAspectAdapter<Caching, Boolean>) this.sharedCacheDefaultHolder; - assertTrue(sharedCacheDefaultAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(subjectCaching.hasAnyPropertyChangeListeners(Caching.SHARED_CACHE_DEFAULT_PROPERTY)); - - sharedCacheDefaultAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheDefaultListener); - assertFalse(subjectCaching.hasAnyPropertyChangeListeners(Caching.SHARED_CACHE_DEFAULT_PROPERTY)); - assertFalse(sharedCacheDefaultAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - /** - * Initializes directly the PU properties before testing. - */ - protected void populatePu() { - this.persistenceUnitPut( - Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE, - CACHE_TYPE_TEST_VALUE); - this.persistenceUnitPut( - Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE, - SHARED_CACHE_TEST_VALUE); - this.persistenceUnitPut( - Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT, - CACHE_TYPE_DEFAULT_TEST_VALUE); - this.persistenceUnitPut( - Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT, - SHARED_CACHE_DEFAULT_TEST_VALUE); - return; - } - - protected PersistenceUnitProperties model() { - return this.caching; - } - - /** ****** CacheType ******* */ - private WritablePropertyValueModel<CacheType> buildCacheTypeAA(PropertyValueModel<Caching> subjectHolder) { - return new PropertyAspectAdapter<Caching, CacheType>(subjectHolder, Caching.CACHE_TYPE_PROPERTY) { - @Override - protected CacheType buildValue_() { - return this.subject.getCacheType(ENTITY_NAME_TEST_VALUE); - } - - @Override - protected void setValue_(CacheType enumValue) { - this.subject.setCacheType(enumValue, ENTITY_NAME_TEST_VALUE); - } - }; - } - - private PropertyChangeListener buildCacheTypeChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CachingValueModelTests.this.cacheTypeEvent = e; - } - }; - } - - /** ****** SharedCache ******* */ - private WritablePropertyValueModel<Boolean> buildSharedCacheAA(PropertyValueModel<Caching> subjectHolder) { - return new PropertyAspectAdapter<Caching, Boolean>(subjectHolder, Caching.SHARED_CACHE_PROPERTY) { - @Override - protected Boolean buildValue_() { - return this.subject.getSharedCache(ENTITY_NAME_TEST_VALUE); - } - - @Override - protected void setValue_(Boolean enumValue) { - this.subject.setSharedCache(enumValue, ENTITY_NAME_TEST_VALUE); - } - }; - } - - private PropertyChangeListener buildSharedCacheChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CachingValueModelTests.this.sharedCacheEvent = e; - } - }; - } - - /** ****** CacheTypeDefault ******* */ - private WritablePropertyValueModel<CacheType> buildCacheTypeDefaultAA(PropertyValueModel<Caching> subjectHolder) { - return new PropertyAspectAdapter<Caching, CacheType>(subjectHolder, Caching.CACHE_TYPE_DEFAULT_PROPERTY) { - @Override - protected CacheType buildValue_() { - return this.subject.getCacheTypeDefault(); - } - - @Override - protected void setValue_(CacheType enumValue) { - this.subject.setCacheTypeDefault(enumValue); - } - }; - } - - private PropertyChangeListener buildCacheTypeDefaultChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CachingValueModelTests.this.cacheTypeDefaultEvent = e; - } - }; - } - - /** ****** SharedCacheDefault ******* */ - private WritablePropertyValueModel<Boolean> buildSharedCacheDefaultAA(PropertyValueModel<Caching> subjectHolder) { - return new PropertyAspectAdapter<Caching, Boolean>(subjectHolder, Caching.SHARED_CACHE_DEFAULT_PROPERTY) { - @Override - protected Boolean buildValue_() { - return this.subject.getSharedCacheDefault(); - } - - @Override - protected void setValue_(Boolean enumValue) { - this.subject.setSharedCacheDefault(enumValue); - } - }; - } - - private PropertyChangeListener buildSharedCacheDefaultChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CachingValueModelTests.this.sharedCacheDefaultEvent = e; - } - }; - } - - /** ****** Tests ******* */ - public void testValue() { - /** ****** CacheType - defaults for entity level caching are equal to the persistence unit settings ******* */ - this.verifyCacheTypeAAValue(CACHE_TYPE_TEST_VALUE); - assertEquals(this.caching.getCacheTypeDefault(), this.caching.getDefaultCacheType()); - /** ****** SharedCache - defaults for entity level caching are equal to the persistence unit settings ******* */ - this.verifySharedCacheAAValue(SHARED_CACHE_TEST_VALUE); - assertEquals(this.caching.getSharedCacheDefault(), this.caching.getDefaultSharedCache()); - /** ****** CacheTypeDefault ******* */ - this.verifyCacheTypeDefaultAAValue(CACHE_TYPE_DEFAULT_TEST_VALUE); - assertEquals(Caching.DEFAULT_CACHE_TYPE_DEFAULT, this.caching.getDefaultCacheTypeDefault()); - /** ****** SharedCacheDefault ******* */ - this.verifySharedCacheDefaultAAValue(SHARED_CACHE_DEFAULT_TEST_VALUE); - assertEquals(Caching.DEFAULT_SHARED_CACHE_DEFAULT, this.caching.getDefaultSharedCacheDefault()); - } - - public void testSetValue() throws Exception { - /** ****** CacheType ******* */ - this.cacheTypeEvent = null; - this.verifyHasListeners(this.cacheTypeHolder, PropertyValueModel.VALUE); - CacheType newCacheType = CacheType.full; - // Modify the property holder - this.cacheTypeHolder.setValue(newCacheType); - this.verifyCacheTypeAAValue(newCacheType); - assertNotNull(this.cacheTypeEvent); - /** ****** SharedCache ******* */ - this.sharedCacheEvent = null; - this.verifyHasListeners(this.sharedCacheHolder, PropertyValueModel.VALUE); - Boolean newSharedCache = !SHARED_CACHE_TEST_VALUE; - // Modify the property holder - this.sharedCacheHolder.setValue(newSharedCache); - this.verifySharedCacheAAValue(newSharedCache); - assertNotNull(this.sharedCacheEvent); - /** ****** CacheTypeDefault ******* */ - this.cacheTypeDefaultEvent = null; - this.verifyHasListeners(this.cacheTypeDefaultHolder, PropertyValueModel.VALUE); - CacheType newCacheTypeDefault = CacheType.none; - // Modify the property holder - this.cacheTypeDefaultHolder.setValue(newCacheTypeDefault); - this.verifyCacheTypeDefaultAAValue(newCacheTypeDefault); - assertNotNull(this.cacheTypeDefaultEvent); - /** ****** SharedCacheDefault ******* */ - this.sharedCacheDefaultEvent = null; - this.verifyHasListeners(this.sharedCacheDefaultHolder, PropertyValueModel.VALUE); - Boolean newSharedCacheDefault = !SHARED_CACHE_DEFAULT_TEST_VALUE; - // Modify the property holder - this.sharedCacheDefaultHolder.setValue(newSharedCacheDefault); - this.verifySharedCacheDefaultAAValue(newSharedCacheDefault); - assertNotNull(this.sharedCacheDefaultEvent); - } - - public void testSetNullValue() { - String notDeleted = "Property not deleted"; - /** ****** CacheType ******* */ - this.cacheTypeEvent = null; - // Setting the property holder - this.cacheTypeHolder.setValue(null); - // testing Holder - this.verifyCacheTypeAAValue(null); - assertNotNull(this.cacheTypeEvent); - // testing PU properties - this.verifyPuHasNotProperty(Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE, notDeleted); - /** ****** SharedCache ******* */ - this.sharedCacheEvent = null; - // Setting the property holder - this.sharedCacheHolder.setValue(null); - // testing Holder - this.verifySharedCacheAAValue(null); - assertNotNull(this.sharedCacheEvent); - // testing PU properties - this.verifyPuHasNotProperty(Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE, notDeleted); - /** ****** CacheTypeDefault ******* */ - this.cacheTypeDefaultEvent = null; - // Setting the property holder - this.cacheTypeDefaultHolder.setValue(null); - // testing Holder - this.verifyCacheTypeDefaultAAValue(null); - assertNotNull(this.cacheTypeDefaultEvent); - // testing PU properties - this.verifyPuHasNotProperty(Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT, notDeleted); - /** ****** SharedCacheDefault ******* */ - this.sharedCacheDefaultEvent = null; - // Setting the property holder - this.sharedCacheDefaultHolder.setValue(null); - // testing Holder - this.verifySharedCacheDefaultAAValue(null); - assertNotNull(this.sharedCacheDefaultEvent); - // testing PU properties - this.verifyPuHasNotProperty(Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT, notDeleted); - } - - /** ****** convenience methods ******* */ - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifyCacheTypeAAValue(CacheType testValue) { - this.verifyAAValue( - testValue, - this.caching.getCacheType(ENTITY_NAME_TEST_VALUE), - this.cacheTypeHolder, - Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE); - } - - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifySharedCacheAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.caching.getSharedCache(ENTITY_NAME_TEST_VALUE), - this.sharedCacheHolder, - Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE); - } - - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifyCacheTypeDefaultAAValue(CacheType testValue) { - this.verifyAAValue( - testValue, - this.caching.getCacheTypeDefault(), - this.cacheTypeDefaultHolder, - Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT); - } - - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifySharedCacheDefaultAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.caching.getSharedCacheDefault(), - this.sharedCacheDefaultHolder, - Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT); - } - - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/JptEclipseLinkCoreCachingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/JptEclipseLinkCoreCachingTests.java deleted file mode 100644 index 5f6d62b720..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/JptEclipseLinkCoreCachingTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.caching; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkCoreCachingTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreCachingTests.class.getPackage().getName()); - - suite.addTestSuite(CachingValueModelTests.class); - suite.addTestSuite(CachingAdapterTests.class); - - return suite; - } - - private JptEclipseLinkCoreCachingTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/connection/ConnectionAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/connection/ConnectionAdapterTests.java deleted file mode 100644 index 31ea1ea5e1..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/connection/ConnectionAdapterTests.java +++ /dev/null @@ -1,586 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2008 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.connection; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitTransactionType; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.context.persistence.GenericProperty; -import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener; -import org.eclipse.jpt.eclipselink.core.internal.context.connection.BatchWriting; -import org.eclipse.jpt.eclipselink.core.internal.context.connection.Connection; -import org.eclipse.jpt.eclipselink.core.internal.context.connection.EclipseLinkConnection; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * ConnectionAdapterTests - */ -public class ConnectionAdapterTests extends PersistenceUnitTestCase -{ - private Connection connection; - - public static final PersistenceUnitTransactionType TRANSACTION_TYPE_TEST_VALUE = PersistenceUnitTransactionType.RESOURCE_LOCAL; - public static final PersistenceUnitTransactionType TRANSACTION_TYPE_TEST_VALUE_2 = PersistenceUnitTransactionType.JTA; - - public static final String JTA_DATA_SOURCE_TEST_VALUE = "Test_JTA"; - public static final String JTA_DATA_SOURCE_TEST_VALUE_2 = "Test_JTA_2"; - - public static final String NON_JTA_DATA_SOURCE_TEST_VALUE = "Test_Non_JTA"; - public static final String NON_JTA_DATA_SOURCE_TEST_VALUE_2 = "Test_Non_JTA_2"; - - public static final String NATIVE_SQL_KEY = Connection.ECLIPSELINK_NATIVE_SQL; - public static final Boolean NATIVE_SQL_TEST_VALUE = false; - public static final Boolean NATIVE_SQL_TEST_VALUE_2 = ! NATIVE_SQL_TEST_VALUE; - - public static final String BATCH_WRITING_KEY = Connection.ECLIPSELINK_BATCH_WRITING; - public static final BatchWriting BATCH_WRITING_TEST_VALUE = BatchWriting.oracle_jdbc; - public static final BatchWriting BATCH_WRITING_TEST_VALUE_2 = BatchWriting.buffered; - - public static final String CACHE_STATEMENTS_KEY = Connection.ECLIPSELINK_CACHE_STATEMENTS; - public static final Boolean CACHE_STATEMENTS_TEST_VALUE = false; - public static final Boolean CACHE_STATEMENTS_TEST_VALUE_2 = ! CACHE_STATEMENTS_TEST_VALUE; - - public static final String CACHE_STATEMENTS_SIZE_KEY = Connection.ECLIPSELINK_CACHE_STATEMENTS_SIZE; - public static final Integer CACHE_STATEMENTS_SIZE_TEST_VALUE = 100; - public static final Integer CACHE_STATEMENTS_SIZE_TEST_VALUE_2 = 200; - - public static final String DRIVER_KEY = Connection.ECLIPSELINK_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 = Connection.ECLIPSELINK_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 = Connection.ECLIPSELINK_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 = Connection.ECLIPSELINK_PASSWORD; - public static final String PASSWORD_TEST_VALUE = "test"; - public static final String PASSWORD_TEST_VALUE_2 = "test_2"; - - public static final String BIND_PARAMETERS_KEY = Connection.ECLIPSELINK_BIND_PARAMETERS; - public static final Boolean BIND_PARAMETERS_TEST_VALUE = false; - public static final Boolean BIND_PARAMETERS_TEST_VALUE_2 = ! BIND_PARAMETERS_TEST_VALUE; - - public static final String READ_CONNECTIONS_SHARED_KEY = Connection.ECLIPSELINK_READ_CONNECTIONS_SHARED; - public static final Boolean READ_CONNECTIONS_SHARED_TEST_VALUE = false; - public static final Boolean READ_CONNECTIONS_SHARED_TEST_VALUE_2 = ! READ_CONNECTIONS_SHARED_TEST_VALUE; - - public static final String READ_CONNECTIONS_MIN_KEY = Connection.ECLIPSELINK_READ_CONNECTIONS_MIN; - public static final Integer READ_CONNECTIONS_MIN_TEST_VALUE = 100; - public static final Integer READ_CONNECTIONS_MIN_TEST_VALUE_2 = 200; - - public static final String READ_CONNECTIONS_MAX_KEY = Connection.ECLIPSELINK_READ_CONNECTIONS_MAX; - public static final Integer READ_CONNECTIONS_MAX_TEST_VALUE = 100; - public static final Integer READ_CONNECTIONS_MAX_TEST_VALUE_2 = 200; - - public static final String WRITE_CONNECTIONS_MIN_KEY = Connection.ECLIPSELINK_WRITE_CONNECTIONS_MIN; - public static final Integer WRITE_CONNECTIONS_MIN_TEST_VALUE = 100; - public static final Integer WRITE_CONNECTIONS_MIN_TEST_VALUE_2 = 200; - - public static final String WRITE_CONNECTIONS_MAX_KEY = Connection.ECLIPSELINK_WRITE_CONNECTIONS_MAX; - public static final Integer WRITE_CONNECTIONS_MAX_TEST_VALUE = 100; - public static final Integer WRITE_CONNECTIONS_MAX_TEST_VALUE_2 = 200; - - public ConnectionAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.connection = this.persistenceUnitProperties.getConnection(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.connection.addPropertyChangeListener(Connection.TRANSACTION_TYPE_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.JTA_DATA_SOURCE_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.NON_JTA_DATA_SOURCE_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.NATIVE_SQL_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.BATCH_WRITING_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.CACHE_STATEMENTS_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.CACHE_STATEMENTS_SIZE_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.DRIVER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.URL_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.USER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.PASSWORD_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.BIND_PARAMETERS_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.READ_CONNECTIONS_SHARED_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.READ_CONNECTIONS_MIN_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.READ_CONNECTIONS_MAX_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.WRITE_CONNECTIONS_MIN_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.WRITE_CONNECTIONS_MAX_PROPERTY, propertyChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 14; // EclipseLink properties - this.propertiesTotal = this.modelPropertiesSizeOriginal + 4; // 4 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - // Initializes EclipseLink properties - this.persistenceUnitPut("misc.property.1", "value.1"); - this.persistenceUnitPut(NATIVE_SQL_KEY, NATIVE_SQL_TEST_VALUE.toString()); - this.persistenceUnitPut(BATCH_WRITING_KEY, BATCH_WRITING_TEST_VALUE); - this.persistenceUnitPut(CACHE_STATEMENTS_KEY, CACHE_STATEMENTS_TEST_VALUE.toString()); - this.persistenceUnitPut(CACHE_STATEMENTS_SIZE_KEY, CACHE_STATEMENTS_SIZE_TEST_VALUE.toString()); - this.persistenceUnitPut(DRIVER_KEY, DRIVER_TEST_VALUE.toString()); - this.persistenceUnitPut(URL_KEY, URL_TEST_VALUE.toString()); - this.persistenceUnitPut(USER_KEY, USER_TEST_VALUE.toString()); - this.persistenceUnitPut(PASSWORD_KEY, PASSWORD_TEST_VALUE.toString()); - this.persistenceUnitPut(BIND_PARAMETERS_KEY, BIND_PARAMETERS_TEST_VALUE.toString()); - this.persistenceUnitPut("misc.property.2", "value.2"); - this.persistenceUnitPut("misc.property.3", "value.3"); - this.persistenceUnitPut(READ_CONNECTIONS_SHARED_KEY, READ_CONNECTIONS_SHARED_TEST_VALUE.toString()); - this.persistenceUnitPut(READ_CONNECTIONS_MIN_KEY, READ_CONNECTIONS_MIN_TEST_VALUE.toString()); - this.persistenceUnitPut(READ_CONNECTIONS_MAX_KEY, READ_CONNECTIONS_MAX_TEST_VALUE.toString()); - this.persistenceUnitPut(WRITE_CONNECTIONS_MIN_KEY, WRITE_CONNECTIONS_MIN_TEST_VALUE.toString()); - this.persistenceUnitPut(WRITE_CONNECTIONS_MAX_KEY, WRITE_CONNECTIONS_MAX_TEST_VALUE.toString()); - this.persistenceUnitPut("misc.property.4", "value.4"); - - // Initializes PU property TransactionType - this.persistenceUnit().setSpecifiedTransactionType(TRANSACTION_TYPE_TEST_VALUE); - this.persistenceUnit().setJtaDataSource(JTA_DATA_SOURCE_TEST_VALUE); - this.persistenceUnit().setNonJtaDataSource(NON_JTA_DATA_SOURCE_TEST_VALUE); - return; - } - - // ********** Listeners tests ********** - public void testHasListeners() throws Exception { - // new - ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter = - (ListAspectAdapter<PersistenceUnit, Property>) ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertiesAdapter(); - GenericProperty ctdProperty = (GenericProperty) this.persistenceUnit().getProperty(NATIVE_SQL_KEY); - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(ctdProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - this.verifyHasListeners(this.connection, Connection.NATIVE_SQL_PROPERTY); - this.verifyHasListeners(this.connection, Connection.BIND_PARAMETERS_PROPERTY); - this.verifyHasListeners(this.connection, Connection.CACHE_STATEMENTS_PROPERTY); - this.verifyHasListeners(this.connection, Connection.READ_CONNECTIONS_SHARED_PROPERTY); - this.verifyHasListeners(this.connection, Connection.BATCH_WRITING_PROPERTY); - this.verifyHasListeners(this.connection, Connection.TRANSACTION_TYPE_PROPERTY); - this.verifyHasListeners(this.connection, Connection.JTA_DATA_SOURCE_PROPERTY); - this.verifyHasListeners(this.connection, Connection.NON_JTA_DATA_SOURCE_PROPERTY); - this.verifyHasListeners(propertyListAdapter); - - EclipseLinkConnection elConnection = (EclipseLinkConnection) this.connection; - PersistenceUnitPropertyListListener propertyListListener = elConnection.propertyListListener(); - propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener); - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); // other properties are still listening - this.verifyHasListeners(this.connection, Connection.NATIVE_SQL_PROPERTY); - this.verifyHasListeners(this.connection, Connection.BIND_PARAMETERS_PROPERTY); - this.verifyHasListeners(this.connection, Connection.CACHE_STATEMENTS_PROPERTY); - this.verifyHasListeners(this.connection, Connection.READ_CONNECTIONS_SHARED_PROPERTY); - this.verifyHasListeners(this.connection, Connection.BATCH_WRITING_PROPERTY); - this.verifyHasListeners(this.connection, Connection.TRANSACTION_TYPE_PROPERTY); - this.verifyHasListeners(this.connection, Connection.JTA_DATA_SOURCE_PROPERTY); - this.verifyHasListeners(this.connection, Connection.NON_JTA_DATA_SOURCE_PROPERTY); - } - - // ********** TransactionType tests ********** - public void testSetTransactionType() throws Exception { - this.verifySetPersistenceUnitProperty(Connection.TRANSACTION_TYPE_PROPERTY, - TRANSACTION_TYPE_TEST_VALUE, - TRANSACTION_TYPE_TEST_VALUE_2); - } - - // ********** JtaDataSource tests ********** - public void testSetJtaDataSource() throws Exception { - this.verifySetPersistenceUnitProperty(Connection.JTA_DATA_SOURCE_PROPERTY, - JTA_DATA_SOURCE_TEST_VALUE, - JTA_DATA_SOURCE_TEST_VALUE_2); - } - - // ********** NonJtaDataSource tests ********** - public void testSetNonJtaDataSource() throws Exception { - this.verifySetPersistenceUnitProperty(Connection.NON_JTA_DATA_SOURCE_PROPERTY, - NON_JTA_DATA_SOURCE_TEST_VALUE, - NON_JTA_DATA_SOURCE_TEST_VALUE_2); - } - - // ********** NativeSql tests ********** - public void testSetNativeSql() throws Exception { - this.verifyModelInitialized( - NATIVE_SQL_KEY, - NATIVE_SQL_TEST_VALUE); - this.verifySetProperty( - NATIVE_SQL_KEY, - NATIVE_SQL_TEST_VALUE, - NATIVE_SQL_TEST_VALUE_2); - } - - public void testAddRemoveNativeSql() throws Exception { - this.verifyAddRemoveProperty( - NATIVE_SQL_KEY, - NATIVE_SQL_TEST_VALUE, - NATIVE_SQL_TEST_VALUE_2); - } - - // ********** BatchWriting tests ********** - public void testSetBatchWriting() throws Exception { - this.verifyModelInitialized( - BATCH_WRITING_KEY, - BATCH_WRITING_TEST_VALUE); - this.verifySetProperty( - BATCH_WRITING_KEY, - BATCH_WRITING_TEST_VALUE, - BATCH_WRITING_TEST_VALUE_2); - } - - public void testAddRemoveBatchWriting() throws Exception { - this.verifyAddRemoveProperty( - BATCH_WRITING_KEY, - BATCH_WRITING_TEST_VALUE, - BATCH_WRITING_TEST_VALUE_2); - } - - // ********** CacheStatements tests ********** - public void testSetCacheStatements() throws Exception { - this.verifyModelInitialized( - CACHE_STATEMENTS_KEY, - CACHE_STATEMENTS_TEST_VALUE); - this.verifySetProperty( - CACHE_STATEMENTS_KEY, - CACHE_STATEMENTS_TEST_VALUE, - CACHE_STATEMENTS_TEST_VALUE_2); - } - - public void testAddRemoveCacheStatements() throws Exception { - this.verifyAddRemoveProperty( - CACHE_STATEMENTS_KEY, - CACHE_STATEMENTS_TEST_VALUE, - CACHE_STATEMENTS_TEST_VALUE_2); - } - - // ********** CacheStatementsSize tests ********** - public void testSetCacheStatementsSize() throws Exception { - this.verifyModelInitialized( - CACHE_STATEMENTS_SIZE_KEY, - CACHE_STATEMENTS_SIZE_TEST_VALUE); - this.verifySetProperty( - CACHE_STATEMENTS_SIZE_KEY, - CACHE_STATEMENTS_SIZE_TEST_VALUE, - CACHE_STATEMENTS_SIZE_TEST_VALUE_2); - } - - public void testAddRemoveCacheStatementsSize() throws Exception { - this.verifyAddRemoveProperty( - CACHE_STATEMENTS_SIZE_KEY, - CACHE_STATEMENTS_SIZE_TEST_VALUE, - CACHE_STATEMENTS_SIZE_TEST_VALUE_2); - } - - // ********** 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); - } - - // ********** BindParameters tests ********** - public void testSetBindParameters() throws Exception { - this.verifyModelInitialized( - BIND_PARAMETERS_KEY, - BIND_PARAMETERS_TEST_VALUE); - this.verifySetProperty( - BIND_PARAMETERS_KEY, - BIND_PARAMETERS_TEST_VALUE, - BIND_PARAMETERS_TEST_VALUE_2); - } - - public void testAddRemoveBindParameters() throws Exception { - this.verifyAddRemoveProperty( - BIND_PARAMETERS_KEY, - BIND_PARAMETERS_TEST_VALUE, - BIND_PARAMETERS_TEST_VALUE_2); - } - - // ********** ReadConnectionsShared tests ********** - public void testSetReadConnectionsShared() throws Exception { - this.verifyModelInitialized( - READ_CONNECTIONS_SHARED_KEY, - READ_CONNECTIONS_SHARED_TEST_VALUE); - this.verifySetProperty( - READ_CONNECTIONS_SHARED_KEY, - READ_CONNECTIONS_SHARED_TEST_VALUE, - READ_CONNECTIONS_SHARED_TEST_VALUE_2); - } - - public void testAddRemoveReadConnectionsShared() throws Exception { - this.verifyAddRemoveProperty( - READ_CONNECTIONS_SHARED_KEY, - READ_CONNECTIONS_SHARED_TEST_VALUE, - READ_CONNECTIONS_SHARED_TEST_VALUE_2); - } - - // ********** ReadConnectionsMin tests ********** - public void testSetReadConnectionsMin() throws Exception { - this.verifyModelInitialized( - READ_CONNECTIONS_MIN_KEY, - READ_CONNECTIONS_MIN_TEST_VALUE); - this.verifySetProperty( - READ_CONNECTIONS_MIN_KEY, - READ_CONNECTIONS_MIN_TEST_VALUE, - READ_CONNECTIONS_MIN_TEST_VALUE_2); - } - - public void testAddRemoveReadConnectionsMin() throws Exception { - this.verifyAddRemoveProperty( - READ_CONNECTIONS_MIN_KEY, - READ_CONNECTIONS_MIN_TEST_VALUE, - READ_CONNECTIONS_MIN_TEST_VALUE_2); - } - - // ********** ReadConnectionsMax tests ********** - public void testSetReadConnectionsMax() throws Exception { - this.verifyModelInitialized( - READ_CONNECTIONS_MAX_KEY, - READ_CONNECTIONS_MAX_TEST_VALUE); - this.verifySetProperty( - READ_CONNECTIONS_MAX_KEY, - READ_CONNECTIONS_MAX_TEST_VALUE, - READ_CONNECTIONS_MAX_TEST_VALUE_2); - } - - public void testAddRemoveReadConnectionsMax() throws Exception { - this.verifyAddRemoveProperty( - READ_CONNECTIONS_MAX_KEY, - READ_CONNECTIONS_MAX_TEST_VALUE, - READ_CONNECTIONS_MAX_TEST_VALUE_2); - } - - // ********** WriteConnectionsMin tests ********** - public void testSetWriteConnectionsMin() throws Exception { - this.verifyModelInitialized( - WRITE_CONNECTIONS_MIN_KEY, - WRITE_CONNECTIONS_MIN_TEST_VALUE); - this.verifySetProperty( - WRITE_CONNECTIONS_MIN_KEY, - WRITE_CONNECTIONS_MIN_TEST_VALUE, - WRITE_CONNECTIONS_MIN_TEST_VALUE_2); - } - - public void testAddRemoveWriteConnectionsMin() throws Exception { - this.verifyAddRemoveProperty( - WRITE_CONNECTIONS_MIN_KEY, - WRITE_CONNECTIONS_MIN_TEST_VALUE, - WRITE_CONNECTIONS_MIN_TEST_VALUE_2); - } - - // ********** WriteConnectionsMax tests ********** - public void testSetWriteConnectionsMax() throws Exception { - this.verifyModelInitialized( - WRITE_CONNECTIONS_MAX_KEY, - WRITE_CONNECTIONS_MAX_TEST_VALUE); - this.verifySetProperty( - WRITE_CONNECTIONS_MAX_KEY, - WRITE_CONNECTIONS_MAX_TEST_VALUE, - WRITE_CONNECTIONS_MAX_TEST_VALUE_2); - } - - public void testAddRemoveWriteConnectionsMax() throws Exception { - this.verifyAddRemoveProperty( - WRITE_CONNECTIONS_MAX_KEY, - WRITE_CONNECTIONS_MAX_TEST_VALUE, - WRITE_CONNECTIONS_MAX_TEST_VALUE_2); - } - - // ********** get/set property ********** - @Override - protected synchronized void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Connection.TRANSACTION_TYPE_PROPERTY)) - this.connection.setTransactionType((PersistenceUnitTransactionType) newValue); - else if (propertyName.equals(Connection.JTA_DATA_SOURCE_PROPERTY)) - this.connection.setJtaDataSource((String) newValue); - else if (propertyName.equals(Connection.NON_JTA_DATA_SOURCE_PROPERTY)) - this.connection.setNonJtaDataSource((String) newValue); - else if (propertyName.equals(Connection.NATIVE_SQL_PROPERTY)) - this.connection.setNativeSql((Boolean) newValue); - else if (propertyName.equals(Connection.BATCH_WRITING_PROPERTY)) - this.connection.setBatchWriting((BatchWriting) newValue); - else if (propertyName.equals(Connection.CACHE_STATEMENTS_PROPERTY)) - this.connection.setCacheStatements((Boolean) newValue); - else if (propertyName.equals(Connection.CACHE_STATEMENTS_SIZE_PROPERTY)) - this.connection.setCacheStatementsSize((Integer) newValue); - else if (propertyName.equals(Connection.DRIVER_PROPERTY)) - this.connection.setDriver((String) newValue); - else if (propertyName.equals(Connection.URL_PROPERTY)) - this.connection.setUrl((String) newValue); - else if (propertyName.equals(Connection.USER_PROPERTY)) - this.connection.setUser((String) newValue); - else if (propertyName.equals(Connection.PASSWORD_PROPERTY)) - this.connection.setPassword((String) newValue); - else if (propertyName.equals(Connection.BIND_PARAMETERS_PROPERTY)) - this.connection.setBindParameters((Boolean) newValue); - else if (propertyName.equals(Connection.READ_CONNECTIONS_SHARED_PROPERTY)) - this.connection.setReadConnectionsShared((Boolean) newValue); - else if (propertyName.equals(Connection.READ_CONNECTIONS_MIN_PROPERTY)) - this.connection.setReadConnectionsMin((Integer) newValue); - else if (propertyName.equals(Connection.READ_CONNECTIONS_MAX_PROPERTY)) - this.connection.setReadConnectionsMax((Integer) newValue); - else if (propertyName.equals(Connection.WRITE_CONNECTIONS_MIN_PROPERTY)) - this.connection.setWriteConnectionsMin((Integer) newValue); - else if (propertyName.equals(Connection.WRITE_CONNECTIONS_MAX_PROPERTY)) - this.connection.setWriteConnectionsMax((Integer) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Connection.TRANSACTION_TYPE_PROPERTY)) - modelValue = this.connection.getTransactionType(); - else if (propertyName.equals(Connection.JTA_DATA_SOURCE_PROPERTY)) - modelValue = this.connection.getJtaDataSource(); - else if (propertyName.equals(Connection.NON_JTA_DATA_SOURCE_PROPERTY)) - modelValue = this.connection.getNonJtaDataSource(); - else if (propertyName.equals(Connection.NATIVE_SQL_PROPERTY)) - modelValue = this.connection.getNativeSql(); - else if (propertyName.equals(Connection.BATCH_WRITING_PROPERTY)) - modelValue = this.connection.getBatchWriting(); - else if (propertyName.equals(Connection.CACHE_STATEMENTS_PROPERTY)) - modelValue = this.connection.getCacheStatements(); - else if (propertyName.equals(Connection.CACHE_STATEMENTS_SIZE_PROPERTY)) - modelValue = this.connection.getCacheStatementsSize(); - else if (propertyName.equals(Connection.DRIVER_PROPERTY)) - modelValue = this.connection.getDriver(); - else if (propertyName.equals(Connection.URL_PROPERTY)) - modelValue = this.connection.getUrl(); - else if (propertyName.equals(Connection.USER_PROPERTY)) - modelValue = this.connection.getUser(); - else if (propertyName.equals(Connection.PASSWORD_PROPERTY)) - modelValue = this.connection.getPassword(); - else if (propertyName.equals(Connection.BIND_PARAMETERS_PROPERTY)) - modelValue = this.connection.getBindParameters(); - else if (propertyName.equals(Connection.READ_CONNECTIONS_SHARED_PROPERTY)) - modelValue = this.connection.getReadConnectionsShared(); - else if (propertyName.equals(Connection.READ_CONNECTIONS_MIN_PROPERTY)) - modelValue = this.connection.getReadConnectionsMin(); - else if (propertyName.equals(Connection.READ_CONNECTIONS_MAX_PROPERTY)) - modelValue = this.connection.getReadConnectionsMax(); - else if (propertyName.equals(Connection.WRITE_CONNECTIONS_MIN_PROPERTY)) - modelValue = this.connection.getWriteConnectionsMin(); - else if (propertyName.equals(Connection.WRITE_CONNECTIONS_MAX_PROPERTY)) - modelValue = this.connection.getWriteConnectionsMax(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected Object getPersistenceUnitProperty(String propertyName) throws NoSuchFieldException { - if (propertyName.equals(Connection.TRANSACTION_TYPE_PROPERTY)) { - return this.persistenceUnit().getSpecifiedTransactionType(); - } - else if (propertyName.equals(Connection.JTA_DATA_SOURCE_PROPERTY)) { - return this.persistenceUnit().getJtaDataSource(); - } - else if (propertyName.equals(Connection.NON_JTA_DATA_SOURCE_PROPERTY)) { - return this.persistenceUnit().getNonJtaDataSource(); - } - this.throwMissingDefinition("getPersistenceUnitProperty", propertyName); - return null; - } - - @Override - protected void setPersistenceUnitProperty(String propertyName, Object newValue) throws NoSuchFieldException { - if (propertyName.equals(Connection.TRANSACTION_TYPE_PROPERTY)) - this.persistenceUnit().setSpecifiedTransactionType((PersistenceUnitTransactionType) newValue); - else if (propertyName.equals(Connection.JTA_DATA_SOURCE_PROPERTY)) - this.persistenceUnit().setJtaDataSource((String) newValue); - else if (propertyName.equals(Connection.NON_JTA_DATA_SOURCE_PROPERTY)) - this.persistenceUnit().setNonJtaDataSource((String) newValue); - else - this.throwMissingDefinition("setPersistenceUnitProperty", propertyName); - } - - protected PersistenceUnitProperties model() { - return this.connection; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/connection/JptEclipseLinkCoreConnectionTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/connection/JptEclipseLinkCoreConnectionTests.java deleted file mode 100644 index 54d89a156d..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/connection/JptEclipseLinkCoreConnectionTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.connection; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkCoreConnectionTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreConnectionTests.class.getPackage().getName()); - -// suite.addTestSuite(ConnectionValueModelTests.class); - suite.addTestSuite(ConnectionAdapterTests.class); - - return suite; - } - - private JptEclipseLinkCoreConnectionTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLinkCoreContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLinkCoreContextModelTests.java deleted file mode 100644 index 3888c11ba7..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLinkCoreContextModelTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * 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.eclipselink.core.tests.internal.context; - -import org.eclipse.jpt.eclipselink.core.tests.internal.context.java.JptEclipseLinkCoreJavaContextModelTests; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptEclipseLinkCoreContextModelTests extends TestCase -{ - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptEclipseLinkCoreContextModelTests.class.getName()); - suite.addTest(JptEclipseLinkCoreJavaContextModelTests.suite(all)); - return suite; - } - - private JptEclipseLinkCoreContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaCachingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaCachingTests.java deleted file mode 100644 index 56dec42f8e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaCachingTests.java +++ /dev/null @@ -1,649 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.CacheCoordinationType; -import org.eclipse.jpt.eclipselink.core.context.CacheType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkExpiryTimeOfDay; -import org.eclipse.jpt.eclipselink.core.context.ExistenceType; -import org.eclipse.jpt.eclipselink.core.context.java.EclipseLinkJavaCaching; -import org.eclipse.jpt.eclipselink.core.context.java.EclipseLinkJavaEntity; -import org.eclipse.jpt.eclipselink.core.context.java.EclipseLinkJavaExpiryTimeOfDay; -import org.eclipse.jpt.eclipselink.core.resource.java.CacheAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.ExistenceCheckingAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class EclipseLinkJavaCachingTests extends EclipseLinkJavaContextModelTestCase -{ - public EclipseLinkJavaCachingTests(String name) { - super(name); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createCacheTypeEnum() throws Exception { - this.createEnumAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "CacheType", "SOFT_WEAK, HARD_WEAK, WEAK, SOFT, FULL, CACHE, NONE;"); - } - - private void createCacheCoordinationTypeEnum() throws Exception { - this.createEnumAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "CacheCoordinationType", "SEND_OBJECT_CHANGES, INVALIDATE_CHANGED_OBJECTS, SEND_NEW_OBJECTS_WITH_CHANGES, NONE;"); - } - - private void createExistenceTypeEnum() throws Exception { - this.createEnumAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "ExistenceType", "CHECK_CACHE, CHECK_DATABASE, ASSUME_EXISTENCE, ASSUME_NON_EXISTENCE;"); - } - - private void createCacheAnnotation() throws Exception { - createCacheTypeEnum(); - createCacheCoordinationTypeEnum(); - createTimeOfDayAnnotation(); - this.createAnnotationAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "Cache", - "CacheType type() default SOFT_WEAK; " + - "int size() default 100; " + - "boolean shared() default true; " + - "int expiry() default -1; " + - "TimeOfDay expiryTimeOfDay() default @TimeOfDay(specified=false); " + - "boolean alwaysRefresh() default false; " + - "boolean refreshOnlyIfNewer() default false; " + - "boolean disableHits() default false; " + - "CacheCoordinationType coordinationType() default SEND_OBJECT_CHANGES;"); - } - - private void createTimeOfDayAnnotation() throws Exception { - this.createAnnotationAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "TimeOfDay", - "int hour() default 0; " + - "int minute() default 0; " + - "int second() default 0; " + - "int millisecond() default 0;"); - } - - private void createExistenceCheckingAnnotation() throws Exception { - createExistenceTypeEnum(); - - this.createAnnotationAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "ExistenceChecking", - "ExistenceType value() default CHECK_CACHE;; " + - "int size() default 100; " + - "boolean shared() default true; " + - "int expiry() default -1; " + - "TimeOfDay expiryTimeOfDay() default @TimeOfDay(specified=false); " + - "boolean alwaysRefresh() default false; " + - "boolean refreshOnlyIfNewer() default false; " + - "boolean disableHits() default false; " + - "CacheCoordinationType coordinationType() default SEND_OBJECT_CHANGES;"); - } - - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createCacheAnnotation(); - createExistenceCheckingAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - public void testSetSpecifiedShared() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(Boolean.TRUE, caching.getShared()); - - caching.setSpecifiedShared(Boolean.FALSE); - - - assertEquals(Boolean.FALSE, entity.getCaching().getSpecifiedShared()); - assertEquals(Boolean.FALSE, entity.getCaching().getShared()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - - assertEquals(Boolean.FALSE, cacheAnnotation.getShared()); - } - - public void testSetSpecifiedSharedFalseUnsetsOtherCacheSettings() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - caching.setSpecifiedType(CacheType.HARD_WEAK); - caching.setSpecifiedSize(Integer.valueOf(500)); - caching.setSpecifiedAlwaysRefresh(Boolean.FALSE); - caching.setSpecifiedRefreshOnlyIfNewer(Boolean.FALSE); - caching.setSpecifiedDisableHits(Boolean.FALSE); - caching.setSpecifiedCoordinationType(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - caching.setExistenceChecking(true); - caching.setSpecifiedExistenceType(ExistenceType.CHECK_CACHE); - caching.setExpiry(Integer.valueOf(8000)); - - caching.setSpecifiedShared(Boolean.FALSE); - - assertEquals(null, caching.getSpecifiedType()); - assertEquals(null, caching.getSpecifiedSize()); - assertEquals(null, caching.getSpecifiedAlwaysRefresh()); - assertEquals(null, caching.getSpecifiedRefreshOnlyIfNewer()); - assertEquals(null, caching.getSpecifiedDisableHits()); - assertEquals(null, caching.getSpecifiedCoordinationType()); - assertEquals(null, caching.getExpiry()); - - - //existence checking is the only thing that isn't unset when shared is set to false - assertTrue(caching.hasExistenceChecking()); - assertEquals(ExistenceType.CHECK_CACHE, caching.getSpecifiedExistenceType()); - - caching.setSpecifiedShared(null); - EclipseLinkExpiryTimeOfDay timeOfDayExpiry = caching.addExpiryTimeOfDay(); - timeOfDayExpiry.setHour(Integer.valueOf(5)); - - caching.setSpecifiedShared(Boolean.FALSE); - assertNull(caching.getExpiryTimeOfDay()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - - assertEquals(Boolean.FALSE, cacheAnnotation.getShared()); - assertNull(cacheAnnotation.getExpiryTimeOfDay()); - } - - public void testGetSpecifiedShared() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(Boolean.TRUE, caching.getShared()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.addAnnotation(EclipseLinkJPA.CACHE); - cacheAnnotation.setShared(Boolean.FALSE); - - assertEquals(Boolean.FALSE, cacheAnnotation.getShared()); - assertEquals(Boolean.FALSE, entity.getCaching().getSpecifiedShared()); - assertEquals(Boolean.FALSE, entity.getCaching().getShared()); - } - - public void testSetSpecifiedType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(CacheType.SOFT_WEAK, caching.getType()); - - caching.setSpecifiedType(CacheType.HARD_WEAK); - - - assertEquals(CacheType.HARD_WEAK, entity.getCaching().getSpecifiedType()); - assertEquals(CacheType.HARD_WEAK, entity.getCaching().getType()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheType.HARD_WEAK, cacheAnnotation.getType()); - - - //set specified type to the same as the default, verify it is not set to default - caching.setSpecifiedType(CacheType.SOFT_WEAK); - assertEquals(CacheType.SOFT_WEAK, caching.getSpecifiedType()); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheType.SOFT_WEAK, cacheAnnotation.getType()); - - caching.setSpecifiedType(null); - assertNull(caching.getSpecifiedType()); - assertEquals(CacheType.SOFT_WEAK, caching.getType()); - } - - public void testGetSpecifiedType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(CacheType.SOFT_WEAK, caching.getType()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.addAnnotation(EclipseLinkJPA.CACHE); - cacheAnnotation.setType(org.eclipse.jpt.eclipselink.core.resource.java.CacheType.HARD_WEAK); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheType.HARD_WEAK, cacheAnnotation.getType()); - assertEquals(CacheType.HARD_WEAK, entity.getCaching().getSpecifiedType()); - assertEquals(CacheType.HARD_WEAK, entity.getCaching().getType()); - } - - public void testSetSpecifiedAlwaysRefresh() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(Boolean.FALSE, caching.getAlwaysRefresh()); - - caching.setSpecifiedAlwaysRefresh(Boolean.FALSE); - - - assertEquals(Boolean.FALSE, entity.getCaching().getSpecifiedAlwaysRefresh()); - assertEquals(Boolean.FALSE, entity.getCaching().getAlwaysRefresh()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - - assertEquals(Boolean.FALSE, cacheAnnotation.getAlwaysRefresh()); - } - - public void testGetSpecifiedAlwaysRefresh() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(Boolean.FALSE, caching.getAlwaysRefresh()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.addAnnotation(EclipseLinkJPA.CACHE); - cacheAnnotation.setAlwaysRefresh(Boolean.TRUE); - - assertEquals(Boolean.TRUE, cacheAnnotation.getAlwaysRefresh()); - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedAlwaysRefresh()); - assertEquals(Boolean.TRUE, entity.getCaching().getAlwaysRefresh()); - } - - public void testSetSpecifiedRefreshOnlyIfNewer() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(Boolean.FALSE, caching.getRefreshOnlyIfNewer()); - - caching.setSpecifiedRefreshOnlyIfNewer(Boolean.TRUE); - - - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, entity.getCaching().getRefreshOnlyIfNewer()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - - assertEquals(Boolean.TRUE, cacheAnnotation.getRefreshOnlyIfNewer()); - } - - public void testGetSpecifiedRefreshOnlyIfNewer() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(Boolean.FALSE, caching.getRefreshOnlyIfNewer()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.addAnnotation(EclipseLinkJPA.CACHE); - cacheAnnotation.setRefreshOnlyIfNewer(Boolean.TRUE); - - assertEquals(Boolean.TRUE, cacheAnnotation.getRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, entity.getCaching().getRefreshOnlyIfNewer()); - } - - public void testSetSpecifiedDisableHits() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(Boolean.FALSE, caching.getDisableHits()); - - caching.setSpecifiedDisableHits(Boolean.TRUE); - - - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedDisableHits()); - assertEquals(Boolean.TRUE, entity.getCaching().getDisableHits()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - - assertEquals(Boolean.TRUE, cacheAnnotation.getDisableHits()); - } - - public void testGetSpecifiedDisableHits() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(Boolean.FALSE, caching.getDisableHits()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.addAnnotation(EclipseLinkJPA.CACHE); - cacheAnnotation.setDisableHits(Boolean.TRUE); - - assertEquals(Boolean.TRUE, cacheAnnotation.getDisableHits()); - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedDisableHits()); - assertEquals(Boolean.TRUE, entity.getCaching().getDisableHits()); - } - - public void testSetSpecifiedCoordinationType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(CacheCoordinationType.SEND_OBJECT_CHANGES, caching.getCoordinationType()); - - caching.setSpecifiedCoordinationType(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - - - assertEquals(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, entity.getCaching().getSpecifiedCoordinationType()); - assertEquals(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, entity.getCaching().getCoordinationType()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, cacheAnnotation.getCoordinationType()); - - - //set specified coordination type to the same as the default, verify it is not set to default - caching.setSpecifiedCoordinationType(CacheCoordinationType.SEND_OBJECT_CHANGES); - assertEquals(CacheCoordinationType.SEND_OBJECT_CHANGES, caching.getSpecifiedCoordinationType()); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType.SEND_OBJECT_CHANGES, cacheAnnotation.getCoordinationType()); - - caching.setSpecifiedCoordinationType(null); - assertNull(caching.getSpecifiedCoordinationType()); - assertEquals(CacheCoordinationType.SEND_OBJECT_CHANGES, caching.getCoordinationType()); - } - - public void testGetSpecifiedCoordinationType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(CacheCoordinationType.SEND_OBJECT_CHANGES, caching.getCoordinationType()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.addAnnotation(EclipseLinkJPA.CACHE); - cacheAnnotation.setCoordinationType(org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, cacheAnnotation.getCoordinationType()); - assertEquals(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, entity.getCaching().getSpecifiedCoordinationType()); - assertEquals(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, entity.getCaching().getCoordinationType()); - } - - public void testHasExistenceChecking() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(false, caching.hasExistenceChecking()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(EclipseLinkJPA.EXISTENCE_CHECKING); - assertEquals(true, caching.hasExistenceChecking()); - - typeResource.removeAnnotation(EclipseLinkJPA.EXISTENCE_CHECKING); - assertEquals(false, caching.hasExistenceChecking()); - } - - public void testSetExistenceChecking() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(false, caching.hasExistenceChecking()); - assertNull(typeResource.getAnnotation(EclipseLinkJPA.EXISTENCE_CHECKING)); - - caching.setExistenceChecking(true); - - assertEquals(true, caching.hasExistenceChecking()); - assertNotNull(typeResource.getAnnotation(EclipseLinkJPA.EXISTENCE_CHECKING)); - } - - public void testGetDefaultExistenceType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(ExistenceType.CHECK_DATABASE, caching.getDefaultExistenceType()); - - caching.setExistenceChecking(true); - assertEquals(ExistenceType.CHECK_CACHE, caching.getDefaultExistenceType()); - } - - public void testGetSpecifiedExistenceType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(ExistenceType.CHECK_DATABASE, caching.getExistenceType()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - ExistenceCheckingAnnotation existenceCheckingAnnotation = (ExistenceCheckingAnnotation) typeResource.addAnnotation(EclipseLinkJPA.EXISTENCE_CHECKING); - existenceCheckingAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType.ASSUME_NON_EXISTENCE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType.ASSUME_NON_EXISTENCE, existenceCheckingAnnotation.getValue()); - assertEquals(ExistenceType.ASSUME_NON_EXISTENCE, entity.getCaching().getSpecifiedExistenceType()); - assertEquals(ExistenceType.ASSUME_NON_EXISTENCE, entity.getCaching().getExistenceType()); - } - - public void testSetSpecifiedExistenceType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertEquals(ExistenceType.CHECK_DATABASE, caching.getExistenceType()); - - caching.setExistenceChecking(true); - caching.setSpecifiedExistenceType(ExistenceType.ASSUME_NON_EXISTENCE); - - - assertEquals(ExistenceType.ASSUME_NON_EXISTENCE, entity.getCaching().getSpecifiedExistenceType()); - assertEquals(ExistenceType.ASSUME_NON_EXISTENCE, entity.getCaching().getExistenceType()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ExistenceCheckingAnnotation existenceCheckingAnnotation = (ExistenceCheckingAnnotation) typeResource.getAnnotation(EclipseLinkJPA.EXISTENCE_CHECKING); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType.ASSUME_NON_EXISTENCE, existenceCheckingAnnotation.getValue()); - - - //set specified coordination type to the same as the default, verify it is not set to default - caching.setSpecifiedExistenceType(ExistenceType.CHECK_DATABASE); - assertEquals(ExistenceType.CHECK_DATABASE, caching.getSpecifiedExistenceType()); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType.CHECK_DATABASE, existenceCheckingAnnotation.getValue()); - - caching.setSpecifiedExistenceType(null); - assertNull(caching.getSpecifiedExistenceType()); - assertEquals(ExistenceType.CHECK_CACHE, caching.getExistenceType()); - } - - public void testGetExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - - assertNull(entity.getCaching().getExpiry()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.addAnnotation(EclipseLinkJPA.CACHE); - assertNull(entity.getCaching().getExpiry()); - - cacheAnnotation.setExpiry(Integer.valueOf(57)); - - assertEquals(Integer.valueOf(57), entity.getCaching().getExpiry()); - - typeResource.removeAnnotation(EclipseLinkJPA.CACHE); - assertNull(entity.getCaching().getExpiry()); - } - - public void testSetExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - caching.setExpiry(Integer.valueOf(58)); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Integer.valueOf(58), cacheAnnotation.getExpiry()); - - - caching.setExpiry(null); - cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertNull(cacheAnnotation); - } - - public void testSetExpiryUnsetsExpiryTimeOfDay() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - caching.addExpiryTimeOfDay(); - caching.getExpiryTimeOfDay().setHour(Integer.valueOf(5)); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Integer.valueOf(5), cacheAnnotation.getExpiryTimeOfDay().getHour()); - - caching.setExpiry(Integer.valueOf(900)); - - assertNull(caching.getExpiryTimeOfDay()); - assertNull(cacheAnnotation.getExpiryTimeOfDay()); - assertEquals(Integer.valueOf(900), cacheAnnotation.getExpiry()); - assertEquals(Integer.valueOf(900), caching.getExpiry()); - } - - public void testGetTimeOfDayExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertNull(caching.getExpiryTimeOfDay()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.addAnnotation(EclipseLinkJPA.CACHE); - - cacheAnnotation.addExpiryTimeOfDay(); - - assertNotNull(caching.getExpiryTimeOfDay()); - } - - public void testAddTimeOfDayExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertNull(caching.getExpiryTimeOfDay()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaExpiryTimeOfDay timeOfDayExpiry = caching.addExpiryTimeOfDay(); - - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertNotNull(cacheAnnotation.getExpiryTimeOfDay()); - assertNotNull(caching.getExpiryTimeOfDay()); - assertEquals(timeOfDayExpiry, caching.getExpiryTimeOfDay()); - } - - public void testRemoveTimeOfDayExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - assertNull(caching.getExpiryTimeOfDay()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.addAnnotation(EclipseLinkJPA.CACHE); - cacheAnnotation.addExpiryTimeOfDay(); - - assertNotNull(caching.getExpiryTimeOfDay()); - - caching.removeExpiryTimeOfDay(); - assertNull(caching.getExpiryTimeOfDay()); - assertNull(typeResource.getAnnotation(EclipseLinkJPA.CACHE)); - } - - public void testAddTimeOfDayExpiryUnsetsExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkJavaEntity entity = (EclipseLinkJavaEntity) javaPersistentType().getMapping(); - EclipseLinkJavaCaching caching = entity.getCaching(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - caching.setExpiry(Integer.valueOf(800)); - CacheAnnotation cacheAnnotation = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Integer.valueOf(800), cacheAnnotation.getExpiry()); - - - caching.addExpiryTimeOfDay(); - - - assertNull(caching.getExpiry()); - assertNull(cacheAnnotation.getExpiry()); - assertNotNull(cacheAnnotation.getExpiryTimeOfDay()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaContextModelTestCase.java deleted file mode 100644 index f7a09e2b02..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaContextModelTestCase.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProvider; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaPlatform; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public class EclipseLinkJavaContextModelTestCase extends ContextModelTestCase -{ - - public static final String ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME = "org.eclipse.persistence.annotations"; - - public EclipseLinkJavaContextModelTestCase(String name) { - super(name); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetDataModelProvider()); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM_ID, EclipseLinkJpaPlatform.ID); - return dataModel; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java deleted file mode 100644 index d298faa418..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * 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.eclipselink.core.tests.internal.context.java; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptEclipseLinkCoreJavaContextModelTests extends TestCase -{ - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptEclipseLinkCoreJavaContextModelTests.class.getName()); - suite.addTestSuite(EclipseLinkJavaCachingTests.class); - return suite; - } - - private JptEclipseLinkCoreJavaContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/CustomizationAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/CustomizationAdapterTests.java deleted file mode 100644 index bdec4f3884..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/CustomizationAdapterTests.java +++ /dev/null @@ -1,565 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.customization; - -import java.util.ListIterator; - -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.context.persistence.GenericProperty; -import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener; -import org.eclipse.jpt.eclipselink.core.internal.context.customization.Customization; -import org.eclipse.jpt.eclipselink.core.internal.context.customization.CustomizerProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.customization.EclipseLinkCustomization; -import org.eclipse.jpt.eclipselink.core.internal.context.customization.Weaving; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * Tests the update of model objects by the Customization adapter when the - * PersistenceUnit changes. - */ -public class CustomizationAdapterTests extends PersistenceUnitTestCase -{ - private Customization customization; - private ListChangeEvent entitiesEvent; - private ListChangeEvent sessionCustomizersEvent; - - public static final String ENTITY_TEST = "Employee"; - public static final String ENTITY_TEST_2 = "Address"; - - public static final String THROW_EXCEPTIONS_KEY = Customization.ECLIPSELINK_THROW_EXCEPTIONS; - public static final Boolean THROW_EXCEPTIONS_TEST_VALUE = false; - public static final Boolean THROW_EXCEPTIONS_TEST_VALUE_2 = ! THROW_EXCEPTIONS_TEST_VALUE; - - public static final String WEAVING_LAZY_KEY = Customization.ECLIPSELINK_WEAVING_LAZY; - public static final Boolean WEAVING_LAZY_TEST_VALUE = false; - public static final Boolean WEAVING_LAZY_TEST_VALUE_2 = ! WEAVING_LAZY_TEST_VALUE; - - public static final String WEAVING_CHANGE_TRACKING_KEY = Customization.ECLIPSELINK_WEAVING_CHANGE_TRACKING; - public static final Boolean WEAVING_CHANGE_TRACKING_TEST_VALUE = false; - public static final Boolean WEAVING_CHANGE_TRACKING_TEST_VALUE_2 = ! WEAVING_CHANGE_TRACKING_TEST_VALUE; - - public static final String WEAVING_FETCH_GROUPS_KEY = Customization.ECLIPSELINK_WEAVING_FETCH_GROUPS; - public static final Boolean WEAVING_FETCH_GROUPS_TEST_VALUE = false; - public static final Boolean WEAVING_FETCH_GROUPS_TEST_VALUE_2 = ! WEAVING_FETCH_GROUPS_TEST_VALUE; - - private static final String SESSION_CUSTOMIZER_KEY = Customization.ECLIPSELINK_SESSION_CUSTOMIZER; - private static final String SESSION_CUSTOMIZER_TEST_VALUE = "java.lang.String"; - private static final String SESSION_CUSTOMIZER_TEST_VALUE_2 = "java.lang.Boolean"; - - public static final String WEAVING_KEY = Customization.ECLIPSELINK_WEAVING; - public static final Weaving WEAVING_TEST_VALUE = Weaving.false_; - public static final Weaving WEAVING_TEST_VALUE_2 = Weaving.static_; - - public static final String CUSTOMIZER_KEY = Customization.ECLIPSELINK_DESCRIPTOR_CUSTOMIZER + ENTITY_TEST; - public static final String CUSTOMIZER_TEST_VALUE = "acme.sessions.DescriptorCustomizer"; - public static final String CUSTOMIZER_TEST_VALUE_2 = "acme.sessions.Customizer"; - - public CustomizationAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.customization = this.persistenceUnitProperties.getCustomization(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.customization.addPropertyChangeListener(Customization.THROW_EXCEPTIONS_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_LAZY_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_CHANGE_TRACKING_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_FETCH_GROUPS_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_PROPERTY, propertyChangeListener); - - this.customization.addPropertyChangeListener(Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY, propertyChangeListener); - - this.customization.addPropertyChangeListener(Customization.SESSION_CUSTOMIZER_PROPERTY, propertyChangeListener); - - ListChangeListener sessionCustomizersChangeListener = this.buildSessionCustomizersChangeListener(); - this.customization.addListChangeListener(Customization.SESSION_CUSTOMIZER_LIST_PROPERTY, sessionCustomizersChangeListener); - - ListChangeListener entitiesChangeListener = this.buildEntitiesChangeListener(); - this.customization.addListChangeListener(Customization.ENTITIES_LIST_PROPERTY, entitiesChangeListener); - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 7; - this.propertiesTotal = this.modelPropertiesSizeOriginal + 4; // 4 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitPut("misc.property.1", "value.1"); - this.persistenceUnitPut(THROW_EXCEPTIONS_KEY, THROW_EXCEPTIONS_TEST_VALUE.toString()); - this.persistenceUnitPut(WEAVING_LAZY_KEY, WEAVING_LAZY_TEST_VALUE.toString()); - this.persistenceUnitPut(WEAVING_CHANGE_TRACKING_KEY, WEAVING_CHANGE_TRACKING_TEST_VALUE.toString()); - this.persistenceUnitPut(WEAVING_FETCH_GROUPS_KEY, WEAVING_FETCH_GROUPS_TEST_VALUE.toString()); - this.persistenceUnitPut("misc.property.2", "value.2"); - this.persistenceUnitPut(SESSION_CUSTOMIZER_KEY, SESSION_CUSTOMIZER_TEST_VALUE.toString()); - this.persistenceUnitPut(WEAVING_KEY, WEAVING_TEST_VALUE); - this.persistenceUnitPut("misc.property.3", "value.3"); - this.persistenceUnitPut("misc.property.4", "value.4"); - this.persistenceUnitPut(CUSTOMIZER_KEY, CUSTOMIZER_TEST_VALUE); - return; - } - - // ********** Listeners ********** - private ListChangeListener buildEntitiesChangeListener() { - return new ListChangeListener() { - public void itemsAdded(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsRemoved(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsReplaced(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsMoved(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void listCleared(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void listChanged(ListChangeEvent e) { - CustomizationAdapterTests.this.entityChanged(e); - } - }; - } - - private ListChangeListener buildSessionCustomizersChangeListener() { - return new ListChangeListener() { - public void itemsAdded(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsRemoved(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsReplaced(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsMoved(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void listCleared(ListChangeEvent e) { - CustomizationAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void listChanged(ListChangeEvent e) { - CustomizationAdapterTests.this.sessionCustomizerChanged(e); - } - }; - } - - @Override - protected void clearEvent() { - super.clearEvent(); - this.entitiesEvent = null; - this.sessionCustomizersEvent = null; - } - - void entityChanged(ListChangeEvent e) { - this.entitiesEvent = e; - } - - void sessionCustomizerChanged(ListChangeEvent e) { - this.sessionCustomizersEvent = e; - } - - // ********** entities list ********** - public void testEntitiesList() throws Exception { - // add - this.clearEvent(); - this.customization.addEntity(ENTITY_TEST_2); - - // verify event received - assertNotNull("No Event Fired.", this.entitiesEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.entitiesEvent.getAspectName(), Customization.ENTITIES_LIST_PROPERTY); - - // remove - this.clearEvent(); - this.customization.removeEntity(ENTITY_TEST_2); - // verify event received - assertNotNull("No Event Fired.", this.entitiesEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.entitiesEvent.getAspectName(), Customization.ENTITIES_LIST_PROPERTY); - } - - // ********** sessionCustomizers list ********** - public void testSessionCustomizersList() throws Exception { - // add - this.clearEvent(); - ClassRef classRef = this.customization.addSessionCustomizer(SESSION_CUSTOMIZER_TEST_VALUE_2); - - // verify event received - assertNotNull("No Event Fired.", this.sessionCustomizersEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.sessionCustomizersEvent.getAspectName(), Customization.SESSION_CUSTOMIZER_LIST_PROPERTY); - - // remove - this.clearEvent(); - - this.customization.removeSessionCustomizer(classRef); - // verify event received - assertNotNull("No Event Fired.", this.sessionCustomizersEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.sessionCustomizersEvent.getAspectName(), Customization.SESSION_CUSTOMIZER_LIST_PROPERTY); - } - - // ********** Listeners tests ********** - public void testHasListeners() throws Exception { - // new - ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter = - (ListAspectAdapter<PersistenceUnit, Property>) ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertiesAdapter(); - GenericProperty ctdProperty = (GenericProperty) this.persistenceUnit().getProperty(THROW_EXCEPTIONS_KEY); - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(ctdProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - this.verifyHasListeners(this.customization, Customization.THROW_EXCEPTIONS_PROPERTY); - this.verifyHasListeners(this.customization, Customization.WEAVING_LAZY_PROPERTY); - this.verifyHasListeners(this.customization, Customization.WEAVING_CHANGE_TRACKING_PROPERTY); - this.verifyHasListeners(this.customization, Customization.WEAVING_FETCH_GROUPS_PROPERTY); - this.verifyHasListeners(propertyListAdapter); - - EclipseLinkCustomization elCustomization = (EclipseLinkCustomization) this.customization; - PersistenceUnitPropertyListListener propertyListListener = elCustomization.propertyListListener(); - propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener); - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); // other properties are still listening - this.verifyHasListeners(this.customization, Customization.THROW_EXCEPTIONS_PROPERTY); - this.verifyHasListeners(this.customization, Customization.WEAVING_LAZY_PROPERTY); - this.verifyHasListeners(this.customization, Customization.WEAVING_CHANGE_TRACKING_PROPERTY); - this.verifyHasListeners(this.customization, Customization.WEAVING_FETCH_GROUPS_PROPERTY); - } - - - - // ********** ThrowExceptions tests ********** - public void testSetThrowExceptions() throws Exception { - this.verifyModelInitialized( - THROW_EXCEPTIONS_KEY, - THROW_EXCEPTIONS_TEST_VALUE); - this.verifySetProperty( - THROW_EXCEPTIONS_KEY, - THROW_EXCEPTIONS_TEST_VALUE, - THROW_EXCEPTIONS_TEST_VALUE_2); - } - - public void testAddRemoveThrowExceptions() throws Exception { - this.verifyAddRemoveProperty( - THROW_EXCEPTIONS_KEY, - THROW_EXCEPTIONS_TEST_VALUE, - THROW_EXCEPTIONS_TEST_VALUE_2); - } - - // ********** WeavingLazy tests ********** - public void testSetWeavingLazy() throws Exception { - this.verifyModelInitialized( - WEAVING_LAZY_KEY, - WEAVING_LAZY_TEST_VALUE); - this.verifySetProperty( - WEAVING_LAZY_KEY, - WEAVING_LAZY_TEST_VALUE, - WEAVING_LAZY_TEST_VALUE_2); - } - - public void testAddRemoveWeavingLazy() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_LAZY_KEY, - WEAVING_LAZY_TEST_VALUE, - WEAVING_LAZY_TEST_VALUE_2); - } - - // ********** WeavingChangeTracking tests ********** - public void testSetWeavingChangeTracking() throws Exception { - this.verifyModelInitialized( - WEAVING_CHANGE_TRACKING_KEY, - WEAVING_CHANGE_TRACKING_TEST_VALUE); - this.verifySetProperty( - WEAVING_CHANGE_TRACKING_KEY, - WEAVING_CHANGE_TRACKING_TEST_VALUE, - WEAVING_CHANGE_TRACKING_TEST_VALUE_2); - } - - public void testAddRemoveWeavingChangeTracking() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_CHANGE_TRACKING_KEY, - WEAVING_CHANGE_TRACKING_TEST_VALUE, - WEAVING_CHANGE_TRACKING_TEST_VALUE_2); - } - - // ********** WeavingFetchGroups tests ********** - public void testSetWeavingFetchGroups() throws Exception { - this.verifyModelInitialized( - WEAVING_FETCH_GROUPS_KEY, - WEAVING_FETCH_GROUPS_TEST_VALUE); - this.verifySetProperty( - WEAVING_FETCH_GROUPS_KEY, - WEAVING_FETCH_GROUPS_TEST_VALUE, - WEAVING_FETCH_GROUPS_TEST_VALUE_2); - } - - public void testAddRemoveWeavingFetchGroups() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_FETCH_GROUPS_KEY, - WEAVING_FETCH_GROUPS_TEST_VALUE, - WEAVING_FETCH_GROUPS_TEST_VALUE_2); - } - - // ********** SessionCustomizer tests ********** - public void testSetSessionCustomizer() throws Exception { - this.verifyModelInitialized( - SESSION_CUSTOMIZER_KEY, - SESSION_CUSTOMIZER_TEST_VALUE); - this.verifySetSessionCustomizationProperty( - Customization.SESSION_CUSTOMIZER_PROPERTY, - SESSION_CUSTOMIZER_KEY, - SESSION_CUSTOMIZER_TEST_VALUE, - SESSION_CUSTOMIZER_TEST_VALUE_2); - } - - public void testAddRemoveSessionCustomizer() throws Exception { - this.verifyAddRemoveSessionCustomizationProperty( - Customization.SESSION_CUSTOMIZER_PROPERTY, - SESSION_CUSTOMIZER_KEY, - SESSION_CUSTOMIZER_TEST_VALUE, - SESSION_CUSTOMIZER_TEST_VALUE_2); - } - - // ********** Weaving tests ********** - /** - * Tests the update of Weaving property by the Customization adapter when - * the PU or the model changes. - */ - public void testSetWeaving() throws Exception { - this.verifyModelInitialized( - WEAVING_KEY, - WEAVING_TEST_VALUE); - this.verifySetProperty( - WEAVING_KEY, - WEAVING_TEST_VALUE, - WEAVING_TEST_VALUE_2); - } - - public void testAddRemoveWeaving() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_KEY, - WEAVING_TEST_VALUE, - WEAVING_TEST_VALUE_2); - } - - // ********** Customization class ********** - /** - * Tests the update of Customization property by the Customization adapter when the - * PU or the model changes. - */ - public void testSetCustomization() throws Exception { - this.verifyModelInitialized( - CUSTOMIZER_KEY, - CUSTOMIZER_TEST_VALUE); - this.verifySetCustomizationProperty( - Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY, - CUSTOMIZER_KEY, - CUSTOMIZER_TEST_VALUE, - CUSTOMIZER_TEST_VALUE_2); - } - - public void testAddRemoveCustomization() throws Exception { - this.verifyAddRemoveCustomizationProperty( - Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY, - CUSTOMIZER_KEY, - CUSTOMIZER_TEST_VALUE, - CUSTOMIZER_TEST_VALUE_2); - } - - - // ****** convenience methods ******* - - // ********** verify SessionCustomizer property ********** - protected void verifySetSessionCustomizationProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - // Basic - this.verifyInitialState(propertyName, key, propertyListAdapter); - - // Replace - this.persistenceUnitPut(key, testValue2, true); - this.propertiesTotal++; - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutSessionCustomizerProperty(propertyName, testValue1); - } - - protected void verifyAddRemoveSessionCustomizationProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.persistenceUnit().removeProperty(key, (String) testValue1); - assertFalse(this.customization.sessionCustomizerExists(key)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - - // Add original Property - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitPut(key, testValue1, true); - this.verifyPutSessionCustomizerProperty(propertyName, testValue1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - } - - protected void verifyPutSessionCustomizerProperty(String propertyName, Object expectedValue) throws Exception { - // verify event received - assertNotNull("No Event Fired.", this.sessionCustomizersEvent); - this.verifySessionCustomizerEvent(propertyName, expectedValue); - } - - protected void verifySessionCustomizerEvent(String propertyName, Object expectedValue) throws Exception { - // verify event value - EclipseLinkCustomization customization = (EclipseLinkCustomization) this.sessionCustomizersEvent.getSource(); - assertTrue(customization.sessionCustomizerExists((String) expectedValue)); - return; - } - - // ********** verify entity property ********** - protected void verifySetCustomizationProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - // Basic - this.verifyInitialState(propertyName, key, propertyListAdapter); - - // Replace - this.persistenceUnitPut(key, testValue2); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutCustomizationProperty(propertyName, ENTITY_TEST, testValue2); - - // Replace by setting model object - this.clearEvent(); - this.setCustomizationProperty(propertyName, ENTITY_TEST, testValue1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutCustomizationProperty(propertyName, ENTITY_TEST, testValue1); - } - - protected void verifyAddRemoveCustomizationProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.persistenceUnit().removeProperty(key); - assertFalse(this.persistenceUnit().containsProperty(key)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - this.verifyPutCustomizationProperty(propertyName, ENTITY_TEST, null); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - - // Add original Property - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitPut(key, testValue1); - this.verifyPutCustomizationProperty(propertyName, ENTITY_TEST, testValue1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - - // Replace - this.persistenceUnitPut(key, testValue2); - this.verifyPutCustomizationProperty(propertyName, ENTITY_TEST, testValue2); - } - - protected void verifyPutCustomizationProperty(String propertyName, String entityName, Object expectedValue) throws Exception { - this.verifyEvent(propertyName); - this.verifyCustomizationEvent(propertyName, entityName, expectedValue); - } - - protected void verifyCustomizationEvent(String propertyName, String entityName, Object expectedValue) throws Exception { - // verify event value - CustomizerProperties customizer = (CustomizerProperties) this.propertyChangedEvent.getNewValue(); - if (propertyName.equals(Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY)) { - assertEquals(expectedValue, customizer.getClassName()); - assertEquals(expectedValue, this.customization.getDescriptorCustomizer(entityName)); - } - else { - this.throwMissingDefinition("verifyCustomizationEvent", propertyName); - } - } - - protected void setCustomizationProperty(String propertyName, String entityName, Object newValue) throws NoSuchFieldException { - if (propertyName.equals(Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY)) - this.customization.setDescriptorCustomizer((String) newValue, entityName); - else - this.throwMissingDefinition("setCustomizationProperty", propertyName); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Customization.THROW_EXCEPTIONS_PROPERTY)) - this.customization.setThrowExceptions((Boolean) newValue); - else if (propertyName.equals(Customization.WEAVING_LAZY_PROPERTY)) - this.customization.setWeavingLazy((Boolean) newValue); - else if (propertyName.equals(Customization.WEAVING_CHANGE_TRACKING_PROPERTY)) - this.customization.setWeavingChangeTracking((Boolean) newValue); - else if (propertyName.equals(Customization.WEAVING_FETCH_GROUPS_PROPERTY)) - this.customization.setWeavingFetchGroups((Boolean) newValue); - else if (propertyName.equals(Customization.SESSION_CUSTOMIZER_PROPERTY)) - this.customization.addSessionCustomizer((String) newValue); - else if (propertyName.equals(Customization.WEAVING_PROPERTY)) - this.customization.setWeaving((Weaving) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Customization.THROW_EXCEPTIONS_PROPERTY)) - modelValue = this.customization.getThrowExceptions(); - else if (propertyName.equals(Customization.WEAVING_PROPERTY)) - modelValue = this.customization.getWeaving(); - else if (propertyName.equals(Customization.WEAVING_LAZY_PROPERTY)) - modelValue = this.customization.getWeavingLazy(); - else if (propertyName.equals(Customization.WEAVING_CHANGE_TRACKING_PROPERTY)) - modelValue = this.customization.getWeavingChangeTracking(); - else if (propertyName.equals(Customization.WEAVING_FETCH_GROUPS_PROPERTY)) - modelValue = this.customization.getWeavingFetchGroups(); - else if (propertyName.equals(Customization.SESSION_CUSTOMIZER_PROPERTY)) { - ListIterator<ClassRef> iterator = this.customization.sessionCustomizers(); - if(iterator.hasNext()) { - modelValue = iterator.next().getClassName(); - } - } - else if (propertyName.equals(Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY)) - modelValue = this.customization.getDescriptorCustomizer(ENTITY_TEST); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - protected PersistenceUnitProperties model() { - return this.customization; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/CustomizationValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/CustomizationValueModelTests.java deleted file mode 100644 index 8c6bb1f06f..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/CustomizationValueModelTests.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.customization; - -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.customization.Customization; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * CustomizationValueModelTests - */ -public class CustomizationValueModelTests extends PersistenceUnitTestCase -{ - private Customization customization; - - private WritablePropertyValueModel<Boolean> throwExceptionsHolder; - private PropertyChangeListener throwExceptionsListener; - private PropertyChangeEvent throwExceptionsEvent; - - public static final String ENTITY_NAME_TEST_VALUE = "Employee"; - public static final Boolean THROW_EXCEPTIONS_TEST_VALUE = Boolean.FALSE; - - public CustomizationValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.customization = this.persistenceUnitProperties.getCustomization(); // Subject - PropertyValueModel<Customization> customizationHolder = new SimplePropertyValueModel<Customization>(this.customization); - - this.throwExceptionsHolder = this.buildThrowExceptionsAA(customizationHolder); - this.throwExceptionsListener = this.buildThrowExceptionsChangeListener(); - this.throwExceptionsHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.throwExceptionsListener); - this.throwExceptionsEvent = null; - } - - public void testHasListeners() { - AbstractModel subjectCustomization = (AbstractModel) this.customization; // Subject - - PropertyAspectAdapter<Customization, Boolean> throwExceptionsAA = - (PropertyAspectAdapter<Customization, Boolean>) this.throwExceptionsHolder; - assertTrue(throwExceptionsAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(subjectCustomization.hasAnyPropertyChangeListeners(Customization.THROW_EXCEPTIONS_PROPERTY)); - - throwExceptionsAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.throwExceptionsListener); - assertFalse(subjectCustomization.hasAnyPropertyChangeListeners(Customization.THROW_EXCEPTIONS_PROPERTY)); - assertFalse(throwExceptionsAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - /** - * Initializes directly the PU properties before testing. - */ - protected void populatePu() { - this.persistenceUnitPut( - Customization.ECLIPSELINK_THROW_EXCEPTIONS, - THROW_EXCEPTIONS_TEST_VALUE); - return; - } - - protected PersistenceUnitProperties model() { - return this.customization; - } - - // ****** ThrowExceptions ******* - private WritablePropertyValueModel<Boolean> buildThrowExceptionsAA(PropertyValueModel<Customization> subjectHolder) { - return new PropertyAspectAdapter<Customization, Boolean>(subjectHolder, Customization.THROW_EXCEPTIONS_PROPERTY) { - @Override - protected Boolean buildValue_() { - return this.subject.getThrowExceptions(); - } - - @Override - protected void setValue_(Boolean enumValue) { - this.subject.setThrowExceptions(enumValue); - } - }; - } - - private PropertyChangeListener buildThrowExceptionsChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CustomizationValueModelTests.this.throwExceptionsEvent = e; - } - }; - } - - // ****** Tests ******* - public void testValue() { - // ****** ThrowExceptions ******* - this.verifyThrowExceptionsAAValue(THROW_EXCEPTIONS_TEST_VALUE); - assertEquals(Customization.DEFAULT_THROW_EXCEPTIONS, this.customization.getDefaultThrowExceptions()); - } - - public void testSetValue() throws Exception { - // ****** ThrowExceptions ******* - this.throwExceptionsEvent = null; - this.verifyHasListeners(this.throwExceptionsHolder, PropertyValueModel.VALUE); - Boolean newThrowExceptions = !THROW_EXCEPTIONS_TEST_VALUE; - // Modify the property holder - this.throwExceptionsHolder.setValue(newThrowExceptions); - this.verifyThrowExceptionsAAValue(newThrowExceptions); - assertNotNull(this.throwExceptionsEvent); - } - - public void testSetNullValue() { - String notDeleted = "Property not deleted"; - // ****** ThrowExceptions ******* - this.throwExceptionsEvent = null; - // Setting the property holder - this.throwExceptionsHolder.setValue(null); - // testing Holder - this.verifyThrowExceptionsAAValue(null); - assertNotNull(this.throwExceptionsEvent); - // testing PU properties - this.verifyPuHasNotProperty(Customization.ECLIPSELINK_THROW_EXCEPTIONS, notDeleted); - } - - // ****** convenience methods ******* - - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifyThrowExceptionsAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.customization.getThrowExceptions(), - this.throwExceptionsHolder, - Customization.ECLIPSELINK_THROW_EXCEPTIONS); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/JptEclipseLinkCoreCustomizationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/JptEclipseLinkCoreCustomizationTests.java deleted file mode 100644 index 6a3a67f24e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/JptEclipseLinkCoreCustomizationTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.customization; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkCoreCustomizationTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreCustomizationTests.class.getPackage().getName()); - - suite.addTestSuite(CustomizationValueModelTests.class); - suite.addTestSuite(CustomizationAdapterTests.class); - - return suite; - } - - private JptEclipseLinkCoreCustomizationTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/JptEclipseLinkCoreLoggingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/JptEclipseLinkCoreLoggingTests.java deleted file mode 100644 index e0983918ff..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/JptEclipseLinkCoreLoggingTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.logging; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkCoreLoggingTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreLoggingTests.class.getPackage().getName()); - - suite.addTestSuite(LoggingValueModelTests.class); - suite.addTestSuite(LoggingAdapterTests.class); - - return suite; - } - - private JptEclipseLinkCoreLoggingTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/LoggingAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/LoggingAdapterTests.java deleted file mode 100644 index fae34ea9ef..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/LoggingAdapterTests.java +++ /dev/null @@ -1,355 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2008 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.logging; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.context.persistence.GenericProperty; -import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener; -import org.eclipse.jpt.eclipselink.core.internal.context.logging.EclipseLinkLogging; -import org.eclipse.jpt.eclipselink.core.internal.context.logging.Logger; -import org.eclipse.jpt.eclipselink.core.internal.context.logging.Logging; -import org.eclipse.jpt.eclipselink.core.internal.context.logging.LoggingLevel; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * Tests the update of model objects by the Logging adapter when the - * PersistenceUnit changes. - */ -public class LoggingAdapterTests extends PersistenceUnitTestCase -{ - private Logging logging; - - public static final String LEVEL_KEY = Logging.ECLIPSELINK_LEVEL; - public static final LoggingLevel LEVEL_TEST_VALUE = LoggingLevel.fine; - public static final LoggingLevel LEVEL_TEST_VALUE_2 = LoggingLevel.finest; - - public static final String TIMESTAMP_KEY = Logging.ECLIPSELINK_TIMESTAMP; - public static final Boolean TIMESTAMP_TEST_VALUE = false; - public static final Boolean TIMESTAMP_TEST_VALUE_2 = ! TIMESTAMP_TEST_VALUE; - - public static final String THREAD_KEY = Logging.ECLIPSELINK_THREAD; - public static final Boolean THREAD_TEST_VALUE = false; - public static final Boolean THREAD_TEST_VALUE_2 = ! THREAD_TEST_VALUE; - - public static final String SESSION_KEY = Logging.ECLIPSELINK_SESSION; - public static final Boolean SESSION_TEST_VALUE = false; - public static final Boolean SESSION_TEST_VALUE_2 = ! SESSION_TEST_VALUE; - - public static final String EXCEPTIONS_KEY = Logging.ECLIPSELINK_EXCEPTIONS; - public static final Boolean EXCEPTIONS_TEST_VALUE = false; - public static final Boolean EXCEPTIONS_TEST_VALUE_2 = ! EXCEPTIONS_TEST_VALUE; - - private static final String LOG_FILE_LOCATION_KEY = Logging.ECLIPSELINK_LOG_FILE_LOCATION; - private static final String LOG_FILE_LOCATION_TEST_VALUE = "C:/temp"; - private static final String LOG_FILE_LOCATION_TEST_VALUE_2 = "C:/tmp"; - - private static final String LOGGER_KEY = Logging.ECLIPSELINK_LOGGER; - private static final Logger LOGGER_TEST_VALUE = Logger.java_logger; - private static final String LOGGER_TEST_VALUE_2 = "custom.logger.test"; - - public LoggingAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.logging = this.persistenceUnitProperties.getLogging(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.logging.addPropertyChangeListener(Logging.LEVEL_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging.TIMESTAMP_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging.THREAD_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging.SESSION_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging.EXCEPTIONS_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging.LOG_FILE_LOCATION_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging.LOGGER_PROPERTY, propertyChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 7; - this.propertiesTotal = this.modelPropertiesSizeOriginal + 4; // 4 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitPut("misc.property.1", "value.1"); - this.persistenceUnitPut(TIMESTAMP_KEY, TIMESTAMP_TEST_VALUE.toString()); - this.persistenceUnitPut("misc.property.2", "value.2"); - this.persistenceUnitPut(LEVEL_KEY, LEVEL_TEST_VALUE); - this.persistenceUnitPut("misc.property.3", "value.3"); - this.persistenceUnitPut(THREAD_KEY, THREAD_TEST_VALUE.toString()); - this.persistenceUnitPut(SESSION_KEY, SESSION_TEST_VALUE.toString()); - this.persistenceUnitPut(EXCEPTIONS_KEY, EXCEPTIONS_TEST_VALUE.toString()); - this.persistenceUnitPut("misc.property.4", "value.4"); - this.persistenceUnitPut(LOG_FILE_LOCATION_KEY, LOG_FILE_LOCATION_TEST_VALUE); - this.persistenceUnitPut(LOGGER_KEY, LOGGER_TEST_VALUE); - return; - } - - // ********** Listeners ********** - - // ********** Listeners tests ********** - public void testHasListeners() throws Exception { - // new - ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter = - (ListAspectAdapter<PersistenceUnit, Property>) ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertiesAdapter(); - GenericProperty ctdProperty = (GenericProperty) this.persistenceUnit().getProperty(TIMESTAMP_KEY); - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(ctdProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - this.verifyHasListeners(this.logging, Logging.TIMESTAMP_PROPERTY); -//TODO ADD OTHER PROPERTIES - this.verifyHasListeners(propertyListAdapter); - - EclipseLinkLogging elLogging = (EclipseLinkLogging) this.logging; - PersistenceUnitPropertyListListener propertyListListener = elLogging.propertyListListener(); - propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener); - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); // other properties are still listening - this.verifyHasListeners(this.logging, Logging.TIMESTAMP_PROPERTY); - } - - - // ********** Level tests ********** - public void testSetLevel() throws Exception { - this.verifyModelInitialized( - LEVEL_KEY, - LEVEL_TEST_VALUE); - this.verifySetProperty( - LEVEL_KEY, - LEVEL_TEST_VALUE, - LEVEL_TEST_VALUE_2); - } - - public void testAddRemoveLevel() throws Exception { - this.verifyAddRemoveProperty( - LEVEL_KEY, - LEVEL_TEST_VALUE, - LEVEL_TEST_VALUE_2); - } - - // ********** Timestamp tests ********** - public void testSetThrowExceptions() throws Exception { - this.verifyModelInitialized( - TIMESTAMP_KEY, - TIMESTAMP_TEST_VALUE); - this.verifySetProperty( - TIMESTAMP_KEY, - TIMESTAMP_TEST_VALUE, - TIMESTAMP_TEST_VALUE_2); - } - - public void testAddRemoveThrowExceptions() throws Exception { - this.verifyAddRemoveProperty( - TIMESTAMP_KEY, - TIMESTAMP_TEST_VALUE, - TIMESTAMP_TEST_VALUE_2); - } - - // ********** Thread tests ********** - public void testSetThread() throws Exception { - this.verifyModelInitialized( - THREAD_KEY, - THREAD_TEST_VALUE); - this.verifySetProperty( - THREAD_KEY, - THREAD_TEST_VALUE, - THREAD_TEST_VALUE_2); - } - - public void testAddRemoveThread() throws Exception { - this.verifyAddRemoveProperty( - THREAD_KEY, - THREAD_TEST_VALUE, - THREAD_TEST_VALUE_2); - } - - // ********** Session tests ********** - public void testSetSession() throws Exception { - this.verifyModelInitialized( - SESSION_KEY, - SESSION_TEST_VALUE); - this.verifySetProperty( - SESSION_KEY, - SESSION_TEST_VALUE, - SESSION_TEST_VALUE_2); - } - - public void testAddRemoveSession() throws Exception { - this.verifyAddRemoveProperty( - SESSION_KEY, - SESSION_TEST_VALUE, - SESSION_TEST_VALUE_2); - } - - // ********** Exceptions tests ********** - public void testSetExceptions() throws Exception { - this.verifyModelInitialized( - EXCEPTIONS_KEY, - EXCEPTIONS_TEST_VALUE); - this.verifySetProperty( - EXCEPTIONS_KEY, - EXCEPTIONS_TEST_VALUE, - EXCEPTIONS_TEST_VALUE_2); - } - - public void testAddRemoveExceptions() throws Exception { - this.verifyAddRemoveProperty( - EXCEPTIONS_KEY, - EXCEPTIONS_TEST_VALUE, - EXCEPTIONS_TEST_VALUE_2); - } - - // ********** LogFileLocation ********** - public void testSetLogFileLocation() throws Exception { - this.verifyModelInitialized( - LOG_FILE_LOCATION_KEY, - LOG_FILE_LOCATION_TEST_VALUE); - this.verifySetProperty( - LOG_FILE_LOCATION_KEY, - LOG_FILE_LOCATION_TEST_VALUE, - LOG_FILE_LOCATION_TEST_VALUE_2); - } - - public void testAddRemoveLogFileLocation() throws Exception { - this.verifyAddRemoveProperty( - LOG_FILE_LOCATION_KEY, - LOG_FILE_LOCATION_TEST_VALUE, - LOG_FILE_LOCATION_TEST_VALUE_2); - } - - // ********** Logger tests ********** - public void testSetLogger() throws Exception { - this.verifyModelInitialized( - LOGGER_KEY, - this.getEclipseLinkStringValueOf(LOGGER_TEST_VALUE)); // model is storing EclipseLinkStringValue - // verify set enum value - this.verifySetProperty( - LOGGER_KEY, - LOGGER_TEST_VALUE, - LOGGER_TEST_VALUE_2); - // verify set custom and literal value - this.verifySetLogger( - LOGGER_KEY, - LOGGER_TEST_VALUE, - LOGGER_TEST_VALUE_2); - } - - public void testAddRemoveLogger() throws Exception { - this.verifyAddRemoveProperty( - LOGGER_KEY, - LOGGER_TEST_VALUE, - LOGGER_TEST_VALUE_2); - } - - /** - * Verifies setting custom logger and literals. - */ - protected void verifySetLogger(String elKey, Object testValue1, Object testValue2) throws Exception { - Property property = this.persistenceUnit().getProperty(elKey); - String propertyName = this.model().propertyIdFor(property); - // test set custom logger. - this.clearEvent(); - this.setProperty(propertyName, testValue2); - this.verifyPutProperty(propertyName, testValue2); - - // test set (Logger) null - this.clearEvent(); - this.logging.setLogger((Logger) null); - assertFalse(this.persistenceUnit().containsProperty(elKey)); - this.verifyPutProperty(propertyName, null); - - // test set enum literal - this.clearEvent(); - this.setProperty(propertyName, testValue1.toString()); - assertTrue(this.persistenceUnit().containsProperty(elKey)); - this.verifyPutProperty(propertyName, this.getEclipseLinkStringValueOf(testValue1)); - - // test set (String) null - this.clearEvent(); - this.logging.setLogger((String) null); - assertFalse(this.persistenceUnit().containsProperty(elKey)); - this.verifyPutProperty(propertyName, null); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Logging.LEVEL_PROPERTY)) - this.logging.setLevel((LoggingLevel) newValue); - else if (propertyName.equals(Logging.TIMESTAMP_PROPERTY)) - this.logging.setTimestamp((Boolean) newValue); - else if (propertyName.equals(Logging.THREAD_PROPERTY)) - this.logging.setThread((Boolean) newValue); - else if (propertyName.equals(Logging.SESSION_PROPERTY)) - this.logging.setSession((Boolean) newValue); - else if (propertyName.equals(Logging.EXCEPTIONS_PROPERTY)) - this.logging.setExceptions((Boolean) newValue); - else if (propertyName.equals(Logging.LOG_FILE_LOCATION_PROPERTY)) - this.logging.setLogFileLocation((String) newValue); - else if (propertyName.equals(Logging.LOGGER_PROPERTY)) { - if (newValue.getClass().isEnum()) - this.logging.setLogger((Logger) newValue); - else - this.logging.setLogger((String) newValue); - } - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Logging.LEVEL_PROPERTY)) - modelValue = this.logging.getLevel(); - else if (propertyName.equals(Logging.TIMESTAMP_PROPERTY)) - modelValue = this.logging.getTimestamp(); - else if (propertyName.equals(Logging.THREAD_PROPERTY)) - modelValue = this.logging.getThread(); - else if (propertyName.equals(Logging.SESSION_PROPERTY)) - modelValue = this.logging.getSession(); - else if (propertyName.equals(Logging.EXCEPTIONS_PROPERTY)) - modelValue = this.logging.getExceptions(); - else if (propertyName.equals(Logging.LOG_FILE_LOCATION_PROPERTY)) - modelValue = this.logging.getLogFileLocation(); - else if (propertyName.equals(Logging.LOGGER_PROPERTY)) - modelValue = this.logging.getLogger(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - Object expectedValue_ = expectedValue; - if (propertyName.equals(Logging.LOGGER_PROPERTY)) { - - expectedValue_ = (expectedValue != null && expectedValue.getClass().isEnum()) ? - this.getEclipseLinkStringValueOf(LOGGER_TEST_VALUE) : // model is storing EclipseLinkStringValue - expectedValue; - } - super.verifyPutProperty(propertyName, expectedValue_); - } - - protected PersistenceUnitProperties model() { - return this.logging; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/LoggingValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/LoggingValueModelTests.java deleted file mode 100644 index 77d9bda2f6..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/LoggingValueModelTests.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.logging; - -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.logging.Logging; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * LoggingValueModelTests - */ -public class LoggingValueModelTests extends PersistenceUnitTestCase -{ - private Logging logging; - - private WritablePropertyValueModel<Boolean> timestampHolder; - private PropertyChangeListener timestampListener; - private PropertyChangeEvent timestampEvent; - - public static final Boolean TIMESTAMP_TEST_VALUE = Boolean.FALSE; - - public LoggingValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.logging = this.persistenceUnitProperties.getLogging(); // Subject - PropertyValueModel<Logging> loggingHolder = new SimplePropertyValueModel<Logging>(this.logging); - - this.timestampHolder = this.buildTimestampAA(loggingHolder); - this.timestampListener = this.buildTimestampChangeListener(); - this.timestampHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.timestampListener); - this.timestampEvent = null; - } - - public void testHasListeners() { - AbstractModel subjectLogging = (AbstractModel) this.logging; // Subject - - PropertyAspectAdapter<Logging, Boolean> timestampAA = - (PropertyAspectAdapter<Logging, Boolean>) this.timestampHolder; - assertTrue(timestampAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(subjectLogging.hasAnyPropertyChangeListeners(Logging.TIMESTAMP_PROPERTY)); - - timestampAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.timestampListener); - assertFalse(subjectLogging.hasAnyPropertyChangeListeners(Logging.TIMESTAMP_PROPERTY)); - assertFalse(timestampAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - /** - * Initializes directly the PU properties before testing. - */ - protected void populatePu() { - this.persistenceUnitPut( - Logging.ECLIPSELINK_TIMESTAMP, - TIMESTAMP_TEST_VALUE); - return; - } - - protected PersistenceUnitProperties model() { - return this.logging; - } - - // ****** Timestamp ******* - private WritablePropertyValueModel<Boolean> buildTimestampAA(PropertyValueModel<Logging> subjectHolder) { - return new PropertyAspectAdapter<Logging, Boolean>(subjectHolder, Logging.TIMESTAMP_PROPERTY) { - @Override - protected Boolean buildValue_() { - return this.subject.getTimestamp(); - } - - @Override - protected void setValue_(Boolean enumValue) { - this.subject.setTimestamp(enumValue); - } - }; - } - - private PropertyChangeListener buildTimestampChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - LoggingValueModelTests.this.timestampEvent = e; - } - }; - } - - // ****** Tests ******* - public void testValue() { - // ****** Timestamp ******* - this.verifyTimestampAAValue(TIMESTAMP_TEST_VALUE); - assertEquals(Logging.DEFAULT_TIMESTAMP, this.logging.getDefaultTimestamp()); - } - - public void testSetValue() throws Exception { - // ****** Timestamp ******* - this.timestampEvent = null; - this.verifyHasListeners(this.timestampHolder, PropertyValueModel.VALUE); - Boolean newTimestamp = !TIMESTAMP_TEST_VALUE; - // Modify the property holder - this.timestampHolder.setValue(newTimestamp); - this.verifyTimestampAAValue(newTimestamp); - assertNotNull(this.timestampEvent); - } - - public void testSetNullValue() { - String notDeleted = "Property not deleted"; - // ****** Timestamp ******* - this.timestampEvent = null; - // Setting the property holder - this.timestampHolder.setValue(null); - // testing Holder - this.verifyTimestampAAValue(null); - assertNotNull(this.timestampEvent); - // testing PU properties - this.verifyPuHasNotProperty(Logging.ECLIPSELINK_TIMESTAMP, notDeleted); - } - - // ****** convenience methods ******* - - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifyTimestampAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.logging.getTimestamp(), - this.timestampHolder, - Logging.ECLIPSELINK_TIMESTAMP); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/options/JptEclipseLinkCoreOptionsTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/options/JptEclipseLinkCoreOptionsTests.java deleted file mode 100644 index bf2b40bf64..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/options/JptEclipseLinkCoreOptionsTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.options; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkCoreOptionsTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreOptionsTests.class.getPackage().getName()); - - suite.addTestSuite(OptionsValueModelTests.class); - suite.addTestSuite(OptionsAdapterTests.class); - - return suite; - } - - private JptEclipseLinkCoreOptionsTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/options/OptionsAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/options/OptionsAdapterTests.java deleted file mode 100644 index cb01ba314b..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/options/OptionsAdapterTests.java +++ /dev/null @@ -1,386 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2008 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.options; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.context.persistence.GenericProperty; -import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener; -import org.eclipse.jpt.eclipselink.core.internal.context.options.EclipseLinkOptions; -import org.eclipse.jpt.eclipselink.core.internal.context.options.Options; -import org.eclipse.jpt.eclipselink.core.internal.context.options.TargetDatabase; -import org.eclipse.jpt.eclipselink.core.internal.context.options.TargetServer; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * Tests the update of model objects by the Logging adapter when the - * PersistenceUnit changes. - */ -public class OptionsAdapterTests extends PersistenceUnitTestCase -{ - private Options options; - - private static final String SESSION_NAME_KEY = Options.ECLIPSELINK_SESSION_NAME; - private static final String SESSION_NAME_TEST_VALUE = "session-name.test"; - private static final String SESSION_NAME_TEST_VALUE_2 = "session-name-2.test"; - - private static final String SESSIONS_XML_KEY = Options.ECLIPSELINK_SESSIONS_XML; - private static final String SESSIONS_XML_TEST_VALUE = "sessions-xml.test"; - private static final String SESSIONS_XML_TEST_VALUE_2 = "sessions-xml-2.test"; - - public static final String TARGET_DATABASE_KEY = Options.ECLIPSELINK_TARGET_DATABASE; - public static final TargetDatabase TARGET_DATABASE_TEST_VALUE = TargetDatabase.cloudscape; - public static final String TARGET_DATABASE_TEST_VALUE_2 = "custom.targetDatabase.test"; - - private static final String TARGET_SERVER_KEY = Options.ECLIPSELINK_TARGET_SERVER; - private static final TargetServer TARGET_SERVER_TEST_VALUE = TargetServer.weblogic_9; - private static final String TARGET_SERVER_TEST_VALUE_2 = "custom.targetServer.test"; - - public static final String INCLUDE_DESCRIPTOR_QUERIES_KEY = Options.ECLIPSELINK_SESSION_INCLUDE_DESCRIPTOR_QUERIES; - public static final Boolean INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE = false; - public static final Boolean INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE_2 = ! INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE; - - public static final String SESSION_EVENT_LISTENER_KEY = Options.ECLIPSELINK_SESSION_EVENT_LISTENER; - public static final String SESSION_EVENT_LISTENER_TEST_VALUE = "acme.CustomSessionEventListener"; - public static final String SESSION_EVENT_LISTENER_TEST_VALUE_2 = "oracle.sessions.CustomSessionEventListener"; - - public OptionsAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.options = this.persistenceUnitProperties.getOptions(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.options.addPropertyChangeListener(Options.SESSION_NAME_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options.SESSIONS_XML_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options.TARGET_DATABASE_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options.TARGET_SERVER_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options.SESSION_EVENT_LISTENER_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener( - Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY, propertyChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 6; - this.propertiesTotal = this.modelPropertiesSizeOriginal + 4; // 4 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitPut(SESSION_NAME_KEY, SESSION_NAME_TEST_VALUE); - this.persistenceUnitPut(SESSIONS_XML_KEY, SESSIONS_XML_TEST_VALUE); - this.persistenceUnitPut("misc.property.1", "value.1"); - this.persistenceUnitPut(INCLUDE_DESCRIPTOR_QUERIES_KEY, INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE.toString()); - this.persistenceUnitPut("misc.property.2", "value.2"); - this.persistenceUnitPut("misc.property.3", "value.3"); - this.persistenceUnitPut(TARGET_DATABASE_KEY, TARGET_DATABASE_TEST_VALUE); - this.persistenceUnitPut(TARGET_SERVER_KEY, TARGET_SERVER_TEST_VALUE); - this.persistenceUnitPut(SESSION_EVENT_LISTENER_KEY, SESSION_EVENT_LISTENER_TEST_VALUE); - this.persistenceUnitPut("misc.property.4", "value.4"); - return; - } - - // ********** Listeners ********** - - // ********** Listeners tests ********** - public void testHasListeners() throws Exception { - // new - ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter = - (ListAspectAdapter<PersistenceUnit, Property>) ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertiesAdapter(); - GenericProperty ctdProperty = (GenericProperty) this.persistenceUnit().getProperty(INCLUDE_DESCRIPTOR_QUERIES_KEY); - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(ctdProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - this.verifyHasListeners(this.options, Options.SESSION_NAME_PROPERTY); - this.verifyHasListeners(this.options, Options.SESSIONS_XML_PROPERTY); - this.verifyHasListeners(this.options, Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY); - this.verifyHasListeners(this.options, Options.TARGET_DATABASE_PROPERTY); - this.verifyHasListeners(this.options, Options.SESSION_EVENT_LISTENER_PROPERTY); - this.verifyHasListeners(propertyListAdapter); - - EclipseLinkOptions elOptions = (EclipseLinkOptions) this.options; - PersistenceUnitPropertyListListener propertyListListener = elOptions.propertyListListener(); - propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener); - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); // other properties are still listening - this.verifyHasListeners(this.options, Options.SESSION_NAME_PROPERTY); - this.verifyHasListeners(this.options, Options.SESSIONS_XML_PROPERTY); - this.verifyHasListeners(this.options, Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY); - this.verifyHasListeners(this.options, Options.TARGET_DATABASE_PROPERTY); - this.verifyHasListeners(this.options, Options.SESSION_EVENT_LISTENER_PROPERTY); - } - - - // ********** SessionName tests ********** - public void testSetSessionName() throws Exception { - this.verifyModelInitialized( - SESSION_NAME_KEY, - SESSION_NAME_TEST_VALUE); - this.verifySetProperty( - SESSION_NAME_KEY, - SESSION_NAME_TEST_VALUE, - SESSION_NAME_TEST_VALUE_2); - } - - public void testAddRemoveSessionName() throws Exception { - this.verifyAddRemoveProperty( - SESSION_NAME_KEY, - SESSION_NAME_TEST_VALUE, - SESSION_NAME_TEST_VALUE_2); - } - - // ********** SessionsXml tests ********** - public void testSetSessionsXml() throws Exception { - this.verifyModelInitialized( - SESSIONS_XML_KEY, - SESSIONS_XML_TEST_VALUE); - this.verifySetProperty( - SESSIONS_XML_KEY, - SESSIONS_XML_TEST_VALUE, - SESSIONS_XML_TEST_VALUE_2); - } - - public void testAddRemoveSessionsXml() throws Exception { - this.verifyAddRemoveProperty( - SESSIONS_XML_KEY, - SESSIONS_XML_TEST_VALUE, - SESSIONS_XML_TEST_VALUE_2); - } - - // ********** IncludeDescriptorQueries tests ********** - public void testSetIncludeDescriptorQueries() throws Exception { - this.verifyModelInitialized( - INCLUDE_DESCRIPTOR_QUERIES_KEY, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE); - this.verifySetProperty( - INCLUDE_DESCRIPTOR_QUERIES_KEY, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE_2); - } - - public void testAddRemoveIncludeDescriptorQueries() throws Exception { - this.verifyAddRemoveProperty( - INCLUDE_DESCRIPTOR_QUERIES_KEY, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE_2); - } - - // ********** TargetDatabase tests ********** - public void testSetTargetDatabase() throws Exception { - this.verifyModelInitialized( - TARGET_DATABASE_KEY, - this.getEclipseLinkStringValueOf(TARGET_DATABASE_TEST_VALUE)); // model is storing EclipseLinkStringValue - this.verifySetProperty( - TARGET_DATABASE_KEY, - TARGET_DATABASE_TEST_VALUE, - TARGET_DATABASE_TEST_VALUE_2); - // verify set custom and literal value - this.verifySetTargetDatabase( - TARGET_DATABASE_KEY, - TARGET_DATABASE_TEST_VALUE, - TARGET_DATABASE_TEST_VALUE_2); - } - - public void testAddRemoveTargetDatabase() throws Exception { - this.verifyAddRemoveProperty( - TARGET_DATABASE_KEY, - TARGET_DATABASE_TEST_VALUE, - TARGET_DATABASE_TEST_VALUE_2); - } - - /** - * Verifies setting custom targetDatabase and literals. - */ - protected void verifySetTargetDatabase(String elKey, Object testValue1, Object testValue2) throws Exception { - Property property = this.persistenceUnit().getProperty(elKey); - String propertyName = this.model().propertyIdFor(property); - // test set custom targetDatabase. - this.clearEvent(); - this.setProperty(propertyName, testValue2); - this.verifyPutProperty(propertyName, testValue2); - - // test set (TargetDatabase) null - this.clearEvent(); - this.options.setTargetDatabase((TargetDatabase) null); - assertFalse(this.persistenceUnit().containsProperty(elKey)); - this.verifyPutProperty(propertyName, null); - - // test set enum literal - this.clearEvent(); - this.setProperty(propertyName, testValue1.toString()); - assertTrue(this.persistenceUnit().containsProperty(elKey)); - this.verifyPutProperty(propertyName, this.getEclipseLinkStringValueOf(testValue1)); - - // test set (String) null - this.clearEvent(); - this.options.setTargetDatabase((String) null); - assertFalse(this.persistenceUnit().containsProperty(elKey)); - this.verifyPutProperty(propertyName, null); - } - - // ********** TargetServer tests ********** - public void testSetTargetServer() throws Exception { - this.verifyModelInitialized( - TARGET_SERVER_KEY, - this.getEclipseLinkStringValueOf(TARGET_SERVER_TEST_VALUE)); // model is storing EclipseLinkStringValue - // verify set enum value - this.verifySetProperty( - TARGET_SERVER_KEY, - TARGET_SERVER_TEST_VALUE, - TARGET_SERVER_TEST_VALUE_2); - // verify set custom and literal value - this.verifySetTargetServer( - TARGET_SERVER_KEY, - TARGET_SERVER_TEST_VALUE, - TARGET_SERVER_TEST_VALUE_2); - } - - public void testAddRemoveTargetServer() throws Exception { - this.verifyAddRemoveProperty( - TARGET_SERVER_KEY, - TARGET_SERVER_TEST_VALUE, - TARGET_SERVER_TEST_VALUE_2); - } - - /** - * Verifies setting custom targetServer and literals. - */ - protected void verifySetTargetServer(String elKey, Object testValue1, Object testValue2) throws Exception { - Property property = this.persistenceUnit().getProperty(elKey); - String propertyName = this.model().propertyIdFor(property); - // test set custom targetServer. - this.clearEvent(); - this.setProperty(propertyName, testValue2); - this.verifyPutProperty(propertyName, testValue2); - - // test set (TargetServer) null - this.clearEvent(); - this.options.setTargetServer((TargetServer) null); - assertFalse(this.persistenceUnit().containsProperty(elKey)); - this.verifyPutProperty(propertyName, null); - - // test set enum literal - this.clearEvent(); - this.setProperty(propertyName, testValue1.toString()); - assertTrue(this.persistenceUnit().containsProperty(elKey)); - this.verifyPutProperty(propertyName, this.getEclipseLinkStringValueOf(testValue1)); - - // test set (String) null - this.clearEvent(); - this.options.setTargetServer((String) null); - assertFalse(this.persistenceUnit().containsProperty(elKey)); - this.verifyPutProperty(propertyName, null); - } - - // ********** EventListener tests ********** - public void testSetEventListener() throws Exception { - this.verifyModelInitialized( - SESSION_EVENT_LISTENER_KEY, - SESSION_EVENT_LISTENER_TEST_VALUE); - this.verifySetProperty( - SESSION_EVENT_LISTENER_KEY, - SESSION_EVENT_LISTENER_TEST_VALUE, - SESSION_EVENT_LISTENER_TEST_VALUE_2); - } - - public void testAddRemoveEventListener() throws Exception { - this.verifyAddRemoveProperty( - SESSION_EVENT_LISTENER_KEY, - SESSION_EVENT_LISTENER_TEST_VALUE, - SESSION_EVENT_LISTENER_TEST_VALUE_2); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Options.SESSION_NAME_PROPERTY)) - this.options.setSessionName((String) newValue); - else if (propertyName.equals(Options.SESSIONS_XML_PROPERTY)) - this.options.setSessionsXml((String) newValue); - else if (propertyName.equals(Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY)) - this.options.setIncludeDescriptorQueries((Boolean) newValue); - else if (propertyName.equals(Options.TARGET_DATABASE_PROPERTY)) - this.setTargetDatabaseProperty(newValue); - else if (propertyName.equals(Options.TARGET_SERVER_PROPERTY)) - this.setTargetServerProperty(newValue); - else if (propertyName.equals(Options.SESSION_EVENT_LISTENER_PROPERTY)) - this.options.setEventListener((String) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - private void setTargetDatabaseProperty(Object newValue) { - if (newValue.getClass().isEnum()) - this.options.setTargetDatabase((TargetDatabase) newValue); - else - this.options.setTargetDatabase((String) newValue); - } - - private void setTargetServerProperty(Object newValue) { - if (newValue.getClass().isEnum()) - this.options.setTargetServer((TargetServer) newValue); - else - this.options.setTargetServer((String) newValue); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Options.SESSION_NAME_PROPERTY)) - modelValue = this.options.getSessionName(); - else if (propertyName.equals(Options.SESSIONS_XML_PROPERTY)) - modelValue = this.options.getSessionsXml(); - else if (propertyName.equals(Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY)) - modelValue = this.options.getIncludeDescriptorQueries(); - else if (propertyName.equals(Options.TARGET_DATABASE_PROPERTY)) - modelValue = this.options.getTargetDatabase(); - else if (propertyName.equals(Options.TARGET_SERVER_PROPERTY)) - modelValue = this.options.getTargetServer(); - else if (propertyName.equals(Options.SESSION_EVENT_LISTENER_PROPERTY)) - modelValue = this.options.getEventListener(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - Object expectedValue_ = expectedValue; - if (propertyName.equals(Options.TARGET_DATABASE_PROPERTY) || - propertyName.equals(Options.TARGET_SERVER_PROPERTY)) { - - expectedValue_ = this.convertToEclipseLinkStringValue(expectedValue); - } - - super.verifyPutProperty(propertyName, expectedValue_); - } - - private String convertToEclipseLinkStringValue(Object expectedValue) { - return (String) ((expectedValue != null && expectedValue.getClass().isEnum()) ? - this.getEclipseLinkStringValueOf(expectedValue) : // model is storing EclipseLinkStringValue - expectedValue); // already a EclipseLinkStringValue - } - - protected PersistenceUnitProperties model() { - return this.options; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/options/OptionsValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/options/OptionsValueModelTests.java deleted file mode 100644 index d5aab317f2..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/options/OptionsValueModelTests.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.options; - -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.options.Options; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * OptionsValueModelTests - */ -public class OptionsValueModelTests extends PersistenceUnitTestCase -{ - private Options options; - - private WritablePropertyValueModel<Boolean> includeDescriptorQueriesHolder; - private PropertyChangeListener includeDescriptorQueriesListener; - private PropertyChangeEvent includeDescriptorQueriesEvent; - - public static final Boolean INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE = Boolean.FALSE; - - public OptionsValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.options = this.persistenceUnitProperties.getOptions(); // Subject - PropertyValueModel<Options> optionsHolder = new SimplePropertyValueModel<Options>(this.options); - - this.includeDescriptorQueriesHolder = this.buildIncludeDescriptorQueriesAA(optionsHolder); - this.includeDescriptorQueriesListener = this.buildIncludeDescriptorQueriesChangeListener(); - this.includeDescriptorQueriesHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.includeDescriptorQueriesListener); - this.includeDescriptorQueriesEvent = null; - } - - public void testHasListeners() { - AbstractModel subjectOptions = (AbstractModel) this.options; // Subject - - PropertyAspectAdapter<Options, Boolean> includeDescriptorQueriesAA = - (PropertyAspectAdapter<Options, Boolean>) this.includeDescriptorQueriesHolder; - assertTrue(includeDescriptorQueriesAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(subjectOptions.hasAnyPropertyChangeListeners(Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY)); - - includeDescriptorQueriesAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.includeDescriptorQueriesListener); - assertFalse(subjectOptions.hasAnyPropertyChangeListeners(Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY)); - assertFalse(includeDescriptorQueriesAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - /** - * Initializes directly the PU properties before testing. - */ - protected void populatePu() { - this.persistenceUnitPut( - Options.ECLIPSELINK_SESSION_INCLUDE_DESCRIPTOR_QUERIES, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE); - return; - } - - protected PersistenceUnitProperties model() { - return this.options; - } - - // ****** IncludeDescriptorQueries ******* - private WritablePropertyValueModel<Boolean> buildIncludeDescriptorQueriesAA(PropertyValueModel<Options> subjectHolder) { - return new PropertyAspectAdapter<Options, Boolean>(subjectHolder, Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY) { - @Override - protected Boolean buildValue_() { - return this.subject.getIncludeDescriptorQueries(); - } - - @Override - protected void setValue_(Boolean enumValue) { - this.subject.setIncludeDescriptorQueries(enumValue); - } - }; - } - - private PropertyChangeListener buildIncludeDescriptorQueriesChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - OptionsValueModelTests.this.includeDescriptorQueriesEvent = e; - } - }; - } - - // ****** Tests ******* - public void testValue() { - // ****** IncludeDescriptorQueries ******* - this.verifyIncludeDescriptorQueriesAAValue(INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE); - assertEquals(Options.DEFAULT_SESSION_INCLUDE_DESCRIPTOR_QUERIES, this.options.getDefaultIncludeDescriptorQueries()); - } - - public void testSetValue() throws Exception { - // ****** IncludeDescriptorQueries ******* - this.includeDescriptorQueriesEvent = null; - this.verifyHasListeners(this.includeDescriptorQueriesHolder, PropertyValueModel.VALUE); - Boolean newIncludeDescriptorQueries = !INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE; - // Modify the property holder - this.includeDescriptorQueriesHolder.setValue(newIncludeDescriptorQueries); - this.verifyIncludeDescriptorQueriesAAValue(newIncludeDescriptorQueries); - assertNotNull(this.includeDescriptorQueriesEvent); - } - - public void testSetNullValue() { - String notDeleted = "Property not deleted"; - // ****** IncludeDescriptorQueries ******* - this.includeDescriptorQueriesEvent = null; - // Setting the property holder - this.includeDescriptorQueriesHolder.setValue(null); - // testing Holder - this.verifyIncludeDescriptorQueriesAAValue(null); - assertNotNull(this.includeDescriptorQueriesEvent); - // testing PU properties - this.verifyPuHasNotProperty(Options.ECLIPSELINK_SESSION_INCLUDE_DESCRIPTOR_QUERIES, notDeleted); - } - - // ****** convenience methods ******* - - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifyIncludeDescriptorQueriesAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.options.getIncludeDescriptorQueries(), - this.includeDescriptorQueriesHolder, - Options.ECLIPSELINK_SESSION_INCLUDE_DESCRIPTOR_QUERIES); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/JptEclipselinkCoreResourceModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/JptEclipselinkCoreResourceModelTests.java deleted file mode 100644 index baf0eba59a..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/JptEclipselinkCoreResourceModelTests.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * 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.eclipselink.core.tests.internal.resource; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.eclipselink.core.tests.internal.resource.java.JptEclipseLinkCoreJavaResourceModelTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.resource.orm.EclipseLinkOrmResourceModelTests; - -public class JptEclipselinkCoreResourceModelTests extends TestCase -{ - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptEclipselinkCoreResourceModelTests.class.getName()); - suite.addTest(JptEclipseLinkCoreJavaResourceModelTests.suite(all)); - suite.addTestSuite(EclipseLinkOrmResourceModelTests.class); - return suite; - } - - private JptEclipselinkCoreResourceModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CacheTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CacheTests.java deleted file mode 100644 index 9f7240a6ba..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CacheTests.java +++ /dev/null @@ -1,489 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.CacheAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType; -import org.eclipse.jpt.eclipselink.core.resource.java.CacheType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.TimeOfDayAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class CacheTests extends EclipseLinkJavaResourceModelTestCase { - - public CacheTests(String name) { - super(name); - } - - private void createCacheTypeEnum() throws Exception { - this.createEnumAndMembers("CacheType", "SOFT_WEAK, HARD_WEAK, WEAK, SOFT, FULL, CACHE, NONE;"); - } - - private void createCacheCoordinationTypeEnum() throws Exception { - this.createEnumAndMembers("CacheCoordinationType", "SEND_OBJECT_CHANGES, INVALIDATE_CHANGED_OBJECTS, SEND_NEW_OBJECTS_WITH_CHANGES, NONE;"); - } - - private void createTimeOfDayAnnotation() throws Exception { - - this.createAnnotationAndMembers("TimeOfDay", - "int hour() default 0; " + - "int minute() default 0; " + - "int second() default 0; " + - "int millisecond() default 0;"); - } - - private void createCacheAnnotation() throws Exception { - createCacheTypeEnum(); - createCacheCoordinationTypeEnum(); - createTimeOfDayAnnotation(); - this.createAnnotationAndMembers("Cache", - "CacheType type() default SOFT_WEAK; " + - "int size() default 100; " + - "boolean shared() default true; " + - "int expiry() default -1; " + - "TimeOfDay expiryTimeOfDay() default @TimeOfDay(specified=false); " + - "boolean alwaysRefresh() default false; " + - "boolean refreshOnlyIfNewer() default false; " + - "boolean disableHits() default false; " + - "CacheCoordinationType coordinationType() default SEND_OBJECT_CHANGES;"); - } - - private ICompilationUnit createTestCache() throws Exception { - createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE, EclipseLinkJPA.CACHE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache"); - } - }); - } - - private ICompilationUnit createTestCacheWithCacheType() throws Exception { - createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE, EclipseLinkJPA.CACHE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(type = CacheType.SOFT)"); - } - }); - } - - private ICompilationUnit createTestCacheWithSize() throws Exception { - createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(size = 50)"); - } - }); - } - - private ICompilationUnit createTestCacheWithExpiry() throws Exception { - createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiry = 50)"); - } - }); - } - - private ICompilationUnit createTestCacheWithExpiryTimeOfDay() throws Exception { - createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE, EclipseLinkJPA.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay)"); - } - }); - } - - private ICompilationUnit createTestCacheWithShared() throws Exception { - this.createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(shared=true)"); - } - }); - } - - private ICompilationUnit createTestCacheWithAlwaysRefresh() throws Exception { - this.createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(alwaysRefresh=true)"); - } - }); - } - - private ICompilationUnit createTestCacheWithRefreshOnlyIfNewer() throws Exception { - this.createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(refreshOnlyIfNewer=true)"); - } - }); - } - - private ICompilationUnit createTestCacheWithDisableHits() throws Exception { - this.createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(disableHits=true)"); - } - }); - } - - private ICompilationUnit createTestExistenceCheckingWithCoordinationType() throws Exception { - createCacheAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE, EclipseLinkJPA.CACHE_COORDINATION_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(coordinationType = CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS)"); - } - }); - } - - public void testCache() throws Exception { - ICompilationUnit cu = this.createTestCache(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertNotNull(cache); - } - - public void testGetType() throws Exception { - ICompilationUnit cu = this.createTestCacheWithCacheType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(CacheType.SOFT, cache.getType()); - } - - public void testSetType() throws Exception { - ICompilationUnit cu = this.createTestCacheWithCacheType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(CacheType.SOFT, cache.getType()); - - cache.setType(CacheType.WEAK); - assertEquals(CacheType.WEAK, cache.getType()); - - assertSourceContains("@Cache(type = WEAK)", cu); - - cache.setType(null); - assertNull(cache.getType()); - - assertSourceDoesNotContain("(type = WEAK)", cu); - assertSourceDoesNotContain("@Cache", cu); - } - - public void testGetSize() throws Exception { - ICompilationUnit cu = this.createTestCacheWithSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Integer.valueOf(50), cache.getSize()); - } - - public void testSetSize() throws Exception { - ICompilationUnit cu = this.createTestCacheWithSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Integer.valueOf(50), cache.getSize()); - - cache.setSize(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), cache.getSize()); - - assertSourceContains("@Cache(size = 80)", cu); - - cache.setSize(null); - assertNull(cache.getSize()); - - assertSourceDoesNotContain("(size = 80)", cu); - assertSourceDoesNotContain("@Cache", cu); - } - - public void testGetShared() throws Exception { - ICompilationUnit cu = this.createTestCacheWithShared(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getShared()); - } - - public void testSetShared() throws Exception { - ICompilationUnit cu = this.createTestCacheWithShared(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getShared()); - - cache.setShared(Boolean.FALSE); - assertEquals(Boolean.FALSE, cache.getShared()); - - assertSourceContains("@Cache(shared=false)", cu); - } - - public void testSetSharedNull() throws Exception { - ICompilationUnit cu = this.createTestCacheWithShared(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getShared()); - - cache.setShared(null); - assertNull(typeResource.getAnnotation(EclipseLinkJPA.CACHE)); - - assertSourceDoesNotContain("@Cache", cu); - } - - public void testGetExpiry() throws Exception { - ICompilationUnit cu = this.createTestCacheWithExpiry(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Integer.valueOf(50), cache.getExpiry()); - } - - public void testSetExpiry() throws Exception { - ICompilationUnit cu = this.createTestCacheWithExpiry(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Integer.valueOf(50), cache.getExpiry()); - - cache.setExpiry(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), cache.getExpiry()); - - assertSourceContains("@Cache(expiry = 80)", cu); - - cache.setExpiry(null); - assertNull(cache.getExpiry()); - - assertSourceDoesNotContain("(expiry = 80)", cu); - assertSourceDoesNotContain("@Cache", cu); - } - - public void testGetExpiryTimeOfDay() throws Exception { - ICompilationUnit cu = this.createTestCacheWithExpiryTimeOfDay(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertNotNull(timeOfDay); - } - - public void testAddExpiryTimeOfDay() throws Exception { - ICompilationUnit cu = this.createTestCache(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - cache.addExpiryTimeOfDay(); - - assertNotNull(cache.getExpiryTimeOfDay()); - - assertSourceContains("@Cache(expiryTimeOfDay=@TimeOfDay)", cu); - } - - public void testRemoveExpiryTimeOfDay() throws Exception { - ICompilationUnit cu = this.createTestCacheWithExpiryTimeOfDay(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - - assertNotNull(cache.getExpiryTimeOfDay()); - - cache.removeExpiryTimeOfDay(); - assertNull(cache.getExpiryTimeOfDay()); - assertSourceDoesNotContain("@Cache(expiryTimeOfDay = @TimeOfDay)", cu); - } - - public void testGetAlwaysRefresh() throws Exception { - ICompilationUnit cu = this.createTestCacheWithAlwaysRefresh(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getAlwaysRefresh()); - } - - public void testSetAlwaysRefresh() throws Exception { - ICompilationUnit cu = this.createTestCacheWithAlwaysRefresh(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getAlwaysRefresh()); - - cache.setAlwaysRefresh(Boolean.FALSE); - assertEquals(Boolean.FALSE, cache.getAlwaysRefresh()); - - assertSourceContains("@Cache(alwaysRefresh=false)", cu); - } - - public void testSetAlwaysRefreshNull() throws Exception { - ICompilationUnit cu = this.createTestCacheWithAlwaysRefresh(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getAlwaysRefresh()); - - cache.setAlwaysRefresh(null); - assertNull(typeResource.getAnnotation(EclipseLinkJPA.CACHE)); - - assertSourceDoesNotContain("@Cache", cu); - } - - public void testGetRefreshOnlyIfNewer() throws Exception { - ICompilationUnit cu = this.createTestCacheWithRefreshOnlyIfNewer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getRefreshOnlyIfNewer()); - } - - public void testSetRefreshOnlyIfNewer() throws Exception { - ICompilationUnit cu = this.createTestCacheWithRefreshOnlyIfNewer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getRefreshOnlyIfNewer()); - - cache.setRefreshOnlyIfNewer(Boolean.FALSE); - assertEquals(Boolean.FALSE, cache.getRefreshOnlyIfNewer()); - - assertSourceContains("@Cache(refreshOnlyIfNewer=false)", cu); - } - - public void testSetRefreshOnlyIfNewerNull() throws Exception { - ICompilationUnit cu = this.createTestCacheWithRefreshOnlyIfNewer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getRefreshOnlyIfNewer()); - - cache.setRefreshOnlyIfNewer(null); - assertNull(typeResource.getAnnotation(EclipseLinkJPA.CACHE)); - - assertSourceDoesNotContain("@Cache", cu); - } - - public void testGetDisableHits() throws Exception { - ICompilationUnit cu = this.createTestCacheWithDisableHits(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getDisableHits()); - } - - public void testSetDisableHits() throws Exception { - ICompilationUnit cu = this.createTestCacheWithDisableHits(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getDisableHits()); - - cache.setDisableHits(Boolean.FALSE); - assertEquals(Boolean.FALSE, cache.getDisableHits()); - - assertSourceContains("@Cache(disableHits=false)", cu); - } - - public void testSetDisableHitsNull() throws Exception { - ICompilationUnit cu = this.createTestCacheWithDisableHits(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(Boolean.TRUE, cache.getDisableHits()); - - cache.setDisableHits(null); - assertNull(typeResource.getAnnotation(EclipseLinkJPA.CACHE)); - - assertSourceDoesNotContain("@Cache", cu); - } - - - public void testGetCoordinationType() throws Exception { - ICompilationUnit cu = this.createTestExistenceCheckingWithCoordinationType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, cache.getCoordinationType()); - } - - public void testSetCoordinationType() throws Exception { - ICompilationUnit cu = this.createTestExistenceCheckingWithCoordinationType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - assertEquals(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, cache.getCoordinationType()); - - cache.setCoordinationType(CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES); - assertEquals(CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, cache.getCoordinationType()); - - assertSourceContains("@Cache(coordinationType = SEND_NEW_OBJECTS_WITH_CHANGES)", cu); - - cache.setCoordinationType(null); - assertNull(cache.getCoordinationType()); - - assertSourceDoesNotContain("(coordinationType = SEND_NEW_OBJECTS_WITH_CHANGES)", cu); - assertSourceDoesNotContain("@Cache", cu); - } - - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConversionValueAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConversionValueAnnotationTests.java deleted file mode 100644 index b2ce39c29a..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConversionValueAnnotationTests.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.ObjectTypeConverterAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class ConversionValueAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ConversionValueAnnotationTests(String name) { - super(name); - } - - private void createObjectTypeConverterAnnotation() throws Exception { - createConversionValueAnnotation(); - this.createAnnotationAndMembers("ObjectTypeConverter", - "String name(); " + - "Class dataType() default void.class; " + - "Class objectType() default void.class; " + - "ConversionValue[] conversionValues(); " + - "String defaultObjectValue() default \"\""); - } - - private void createConversionValueAnnotation() throws Exception { - this.createAnnotationAndMembers("ConversionValue", - " String dataValue(); " + - " String objectValue(); "); - } - - private ICompilationUnit createTestObjectTypeConverter() throws Exception { - createObjectTypeConverterAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithConversionValues() throws Exception { - createObjectTypeConverterAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.OBJECT_TYPE_CONVERTER, EclipseLinkJPA.CONVERSION_VALUE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue=\"F\", objectValue = \"Female\"), @ConversionValue(dataValue=\"M\", objectValue = \"Male\")})"); - } - }); - } - - - public void testGetDataValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("F", converter.conversionValueAt(0).getDataValue()); - } - - public void testSetDataValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("F", converter.conversionValueAt(0).getDataValue()); - - converter.conversionValueAt(0).setDataValue("FOO"); - assertEquals("FOO", converter.conversionValueAt(0).getDataValue()); - - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue=\"FOO\", objectValue = \"Female\"), @ConversionValue(dataValue=\"M\", objectValue = \"Male\")})", cu); - } - - public void testSetDataValueNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals(0, converter.conversionValuesSize()); - - converter.addConversionValue(0).setDataValue("FOO"); - assertSourceContains("@ObjectTypeConverter(conversionValues=@ConversionValue(dataValue=\"FOO\"))", cu); - - converter.conversionValueAt(0).setDataValue(null); - assertSourceContains("@ObjectTypeConverter(conversionValues=@ConversionValue)", cu); - assertEquals(1, converter.conversionValuesSize()); - } - - public void testGetObjectValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("Female", converter.conversionValueAt(0).getObjectValue()); - } - - public void testSetObjectValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("Female", converter.conversionValueAt(0).getObjectValue()); - - converter.conversionValueAt(0).setObjectValue("FOO"); - assertEquals("FOO", converter.conversionValueAt(0).getObjectValue()); - - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue=\"F\", objectValue = \"FOO\"), @ConversionValue(dataValue=\"M\", objectValue = \"Male\")})", cu); - } - - public void testSetObjectValueNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals(0, converter.conversionValuesSize()); - - converter.addConversionValue(0).setObjectValue("FOO"); - assertSourceContains("@ObjectTypeConverter(conversionValues=@ConversionValue(objectValue=\"FOO\"))", cu); - - converter.conversionValueAt(0).setObjectValue(null); - assertSourceContains("@ObjectTypeConverter(conversionValues=@ConversionValue)", cu); - assertEquals(1, converter.conversionValuesSize()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java deleted file mode 100644 index b8d4e80782..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.ConvertAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class ConvertAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ConvertAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestConvert() throws Exception { - this.createAnnotationAndMembers("Convert", "String value() default \"none\""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CONVERT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert"); - } - }); - } - - private ICompilationUnit createTestConverterWithValue() throws Exception { - this.createAnnotationAndMembers("Convert", "String value() default \"none\""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CONVERT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(value=\"myConverter\")"); - } - }); - } - - public void testConvertAnnotation() throws Exception { - ICompilationUnit cu = this.createTestConvert(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERT)); - - attributeResource.removeAnnotation(EclipseLinkJPA.CONVERT); - assertNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERT)); - - attributeResource.addAnnotation(EclipseLinkJPA.CONVERT); - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERT)); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestConverterWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ConvertAnnotation convert = (ConvertAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERT); - assertEquals("myConverter", convert.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestConverterWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ConvertAnnotation convert = (ConvertAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERT); - assertEquals("myConverter", convert.getValue()); - - convert.setValue("Bar"); - assertEquals("Bar", convert.getValue()); - - assertSourceContains("@Convert(value=\"Bar\")", cu); - } - - public void testSetValueNull() throws Exception { - ICompilationUnit cu = this.createTestConverterWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ConvertAnnotation convert = (ConvertAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERT); - assertEquals("myConverter", convert.getValue()); - - convert.setValue(null); - assertNull(convert.getValue()); - - assertSourceContains("@Convert", cu); - assertSourceDoesNotContain("value", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java deleted file mode 100644 index 1a5e739548..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.ConverterAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class ConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ConverterAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestConverter() throws Exception { - this.createAnnotationAndMembers("Converter", "String name(); Class converterClass()"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Converter"); - } - }); - } - - private ICompilationUnit createTestConverterWithConverterClass() throws Exception { - this.createAnnotationAndMembers("Converter", "String name(); Class converterClass()"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Converter(converterClass=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestConverterWithName() throws Exception { - this.createAnnotationAndMembers("Converter", "String name(); Class converterClass()"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Converter(name=\"bar\")"); - } - }); - } - - public void testConverterAnnotation() throws Exception { - ICompilationUnit cu = this.createTestConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER)); - - attributeResource.removeAnnotation(EclipseLinkJPA.CONVERTER); - assertNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER)); - - attributeResource.addAnnotation(EclipseLinkJPA.CONVERTER); - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER)); - } - - public void testGetConverterClass() throws Exception { - ICompilationUnit cu = this.createTestConverterWithConverterClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER); - assertEquals("Foo", converter.getConverterClass()); - } - - public void testSetConverterClass() throws Exception { - ICompilationUnit cu = this.createTestConverterWithConverterClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER); - assertEquals("Foo", converter.getConverterClass()); - - converter.setConverterClass("Bar"); - assertEquals("Bar", converter.getConverterClass()); - - assertSourceContains("@Converter(converterClass=Bar.class)", cu); - } - - public void testSetConverterClassNull() throws Exception { - ICompilationUnit cu = this.createTestConverterWithConverterClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER); - assertEquals("Foo", converter.getConverterClass()); - - converter.setConverterClass(null); - assertNull(converter.getConverterClass()); - - assertSourceContains("@Converter", cu); - assertSourceDoesNotContain("converterClass", cu); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER); - assertEquals("bar", converter.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName("foo"); - assertEquals("foo", converter.getName()); - - assertSourceContains("@Converter(name=\"foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName(null); - assertNull(converter.getName()); - - assertSourceContains("@Converter", cu); - assertSourceDoesNotContain("name=", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java deleted file mode 100644 index 2341d05f63..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.resource.java; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.SimpleJpaProjectConfig; -import org.eclipse.jpt.core.tests.internal.resource.java.JavaResourceModelTestCase; -import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaPlatform; - -public class EclipseLinkJavaResourceModelTestCase extends JavaResourceModelTestCase -{ - - public static final String ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME = "org.eclipse.persistence.annotations"; - - public EclipseLinkJavaResourceModelTestCase(String name) { - super(name); - } - - @Override - protected ICompilationUnit createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - return createAnnotationAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, annotationName, annotationBody); - } - - @Override - protected ICompilationUnit createEnumAndMembers(String enumName, String enumBody) throws Exception { - return createEnumAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, enumName, enumBody); - } - - @Override - protected JpaProject.Config buildJpaProjectConfig(IProject project) { - JptCorePlugin.setJpaPlatformId(project, EclipseLinkJpaPlatform.ID); - - SimpleJpaProjectConfig config = new SimpleJpaProjectConfig(); - config.setProject(project); - config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project)); - config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project)); - config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project)); - return config; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ExistenceCheckingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ExistenceCheckingTests.java deleted file mode 100644 index ffe7e71ba9..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ExistenceCheckingTests.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.ExistenceCheckingAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class ExistenceCheckingTests extends EclipseLinkJavaResourceModelTestCase { - - public ExistenceCheckingTests(String name) { - super(name); - } - - private void createExistenceTypeEnum() throws Exception { - this.createEnumAndMembers("ExistenceType", "CHECK_CACHE, CHECK_DATABASE, ASSUME_EXISTENCE, ASSUME_NON_EXISTENCE;"); - } - - private void createExistenceCheckingAnnotation() throws Exception { - this.createAnnotationAndMembers("ExistenceChecking", "ExistenceType value() default CHECK_CACHE;"); - createExistenceTypeEnum(); - } - - private ICompilationUnit createTestExistenceChecking() throws Exception { - createExistenceCheckingAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.EXISTENCE_CHECKING, EclipseLinkJPA.EXISTENCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@ExistenceChecking"); - } - }); - } - - private ICompilationUnit createTestExistenceCheckingWithValue() throws Exception { - createExistenceCheckingAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.EXISTENCE_CHECKING, EclipseLinkJPA.EXISTENCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@ExistenceChecking(ExistenceType.ASSUME_EXISTENCE)"); - } - }); - } - - public void testExistenceChecking() throws Exception { - ICompilationUnit cu = this.createTestExistenceChecking(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - ExistenceCheckingAnnotation existenceChecking = (ExistenceCheckingAnnotation) typeResource.getAnnotation(EclipseLinkJPA.EXISTENCE_CHECKING); - assertNotNull(existenceChecking); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestExistenceCheckingWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - ExistenceCheckingAnnotation existenceChecking = (ExistenceCheckingAnnotation) typeResource.getAnnotation(EclipseLinkJPA.EXISTENCE_CHECKING); - assertEquals(ExistenceType.ASSUME_EXISTENCE, existenceChecking.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestExistenceCheckingWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - ExistenceCheckingAnnotation existenceChecking = (ExistenceCheckingAnnotation) typeResource.getAnnotation(EclipseLinkJPA.EXISTENCE_CHECKING); - assertEquals(ExistenceType.ASSUME_EXISTENCE, existenceChecking.getValue()); - - existenceChecking.setValue(ExistenceType.ASSUME_NON_EXISTENCE); - assertEquals(ExistenceType.ASSUME_NON_EXISTENCE, existenceChecking.getValue()); - - assertSourceContains("@ExistenceChecking(ASSUME_NON_EXISTENCE)", cu); - - existenceChecking.setValue(null); - assertNull(existenceChecking.getValue()); - - assertSourceDoesNotContain("(ASSUME_NON_EXISTENCE)", cu); - assertSourceContains("@ExistenceChecking", cu); - assertSourceDoesNotContain("@ExistenceChecking(", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java deleted file mode 100644 index 2bfc1fa8b6..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.resource.java; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptEclipseLinkCoreJavaResourceModelTests { - - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptEclipseLinkCoreJavaResourceModelTests.class.getName()); - - suite.addTestSuite(CacheTests.class); - suite.addTestSuite(ConversionValueAnnotationTests.class); - suite.addTestSuite(ConvertAnnotationTests.class); - suite.addTestSuite(ConverterAnnotationTests.class); - suite.addTestSuite(ExistenceCheckingTests.class); - suite.addTestSuite(MutableAnnotationTests.class); - suite.addTestSuite(ObjectTypeConverterAnnotationTests.class); - suite.addTestSuite(ReadTransformerAnnotationTests.class); - suite.addTestSuite(StructConverterAnnotationTests.class); - suite.addTestSuite(TimeOfDayTests.class); - suite.addTestSuite(TransformationAnnotationTests.class); - suite.addTestSuite(TypeConverterAnnotationTests.class); - suite.addTestSuite(WriteTransformerAnnotationTests.class); - - return suite; - } - - private JptEclipseLinkCoreJavaResourceModelTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java deleted file mode 100644 index eeb2415c08..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.MutableAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class MutableAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public MutableAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestMutable() throws Exception { - this.createAnnotationAndMembers("Mutable", "boolean value() default true;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.MUTABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Mutable"); - } - }); - } - - private ICompilationUnit createTestMutableWithValue() throws Exception { - this.createAnnotationAndMembers("Mutable", "boolean value() default true;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.MUTABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Mutable(value=true)"); - } - }); - } - - - - public void testMutableAnnotation() throws Exception { - ICompilationUnit cu = this.createTestMutable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE)); - - attributeResource.removeAnnotation(EclipseLinkJPA.MUTABLE); - assertNull(attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE)); - - attributeResource.addAnnotation(EclipseLinkJPA.MUTABLE); - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE)); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestMutableWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MutableAnnotation mutableAnnotation = (MutableAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE); - assertEquals(Boolean.TRUE, mutableAnnotation.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestMutableWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MutableAnnotation mutableAnnotation = (MutableAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE); - assertEquals(Boolean.TRUE, mutableAnnotation.getValue()); - - mutableAnnotation.setValue(Boolean.FALSE); - assertEquals(Boolean.FALSE, mutableAnnotation.getValue()); - - assertSourceContains("@Mutable(value=false)", cu); - - mutableAnnotation.setValue(null); - mutableAnnotation.setValue(Boolean.FALSE); - assertSourceContains("@Mutable(false)", cu); - } - - public void testSetValueNull() throws Exception { - ICompilationUnit cu = this.createTestMutableWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MutableAnnotation mutableAnnotation = (MutableAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE); - assertEquals(Boolean.TRUE, mutableAnnotation.getValue()); - - mutableAnnotation.setValue(null); - assertNull(mutableAnnotation.getValue()); - - assertSourceContains("@Mutable", cu); - assertSourceDoesNotContain("value", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ObjectTypeConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ObjectTypeConverterAnnotationTests.java deleted file mode 100644 index 9308dcd18b..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ObjectTypeConverterAnnotationTests.java +++ /dev/null @@ -1,439 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.ConversionValueAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.ObjectTypeConverterAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class ObjectTypeConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ObjectTypeConverterAnnotationTests(String name) { - super(name); - } - - private void createObjectTypeConverterAnnotation() throws Exception { - createConversionValueAnnotation(); - this.createAnnotationAndMembers("ObjectTypeConverter", - "String name(); " + - "Class dataType() default void.class; " + - "Class objectType() default void.class; " + - "ConversionValue[] conversionValues(); " + - "String defaultObjectValue() default \"\""); - } - - private void createConversionValueAnnotation() throws Exception { - this.createAnnotationAndMembers("ConversionValue", - " String dataValue(); " + - " String objectValue(); "); - } - - private ICompilationUnit createTestObjectTypeConverter() throws Exception { - createObjectTypeConverterAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithDataType() throws Exception { - createObjectTypeConverterAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(dataType=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithObjectType() throws Exception { - createObjectTypeConverterAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(objectType=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithName() throws Exception { - createObjectTypeConverterAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(name=\"bar\")"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithDefaultObjectValue() throws Exception { - createObjectTypeConverterAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(defaultObjectValue=\"f\")"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithConversionValues() throws Exception { - createObjectTypeConverterAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.OBJECT_TYPE_CONVERTER, EclipseLinkJPA.CONVERSION_VALUE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue=\"F\", objectValue = \"Female\"), @ConversionValue(dataValue=\"M\", objectValue = \"Male\")})"); - } - }); - } - - public void testObjectTypeConverterAnnotation() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER)); - - attributeResource.removeAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertNull(attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER)); - - attributeResource.addAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER)); - } - - public void testGetDataType() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - } - - public void testSetDataType() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType("Bar"); - assertEquals("Bar", converter.getDataType()); - - assertSourceContains("@ObjectTypeConverter(dataType=Bar.class)", cu); - } - - public void testSetDataTypeNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType(null); - assertNull(converter.getDataType()); - - assertSourceContains("@ObjectTypeConverter", cu); - assertSourceDoesNotContain("dataType", cu); - } - - public void testGetObjectType() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - } - - public void testSetObjectType() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType("Bar"); - assertEquals("Bar", converter.getObjectType()); - - assertSourceContains("@ObjectTypeConverter(objectType=Bar.class)", cu); - } - - public void testSetObjectTypeNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType(null); - assertNull(converter.getObjectType()); - - assertSourceContains("@ObjectTypeConverter", cu); - assertSourceDoesNotContain("objectType", cu); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName("foo"); - assertEquals("foo", converter.getName()); - - assertSourceContains("@ObjectTypeConverter(name=\"foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName(null); - assertNull(converter.getName()); - - assertSourceContains("@ObjectTypeConverter", cu); - assertSourceDoesNotContain("name=", cu); - } - - - public void testGetDefaultObjectValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDefaultObjectValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("f", converter.getDefaultObjectValue()); - } - - public void testSetDefaultObjectValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDefaultObjectValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("f", converter.getDefaultObjectValue()); - - converter.setDefaultObjectValue("foo"); - assertEquals("foo", converter.getDefaultObjectValue()); - - assertSourceContains("@ObjectTypeConverter(defaultObjectValue=\"foo\")", cu); - } - - public void testSetDefaultObjectValueNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDefaultObjectValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - assertEquals("f", converter.getDefaultObjectValue()); - - converter.setDefaultObjectValue(null); - assertNull(converter.getDefaultObjectValue()); - - assertSourceContains("@ObjectTypeConverter", cu); - assertSourceDoesNotContain("defaultObjectValue", cu); - } - - public void testConversionValues() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - - assertEquals(0, converter.conversionValuesSize()); - assertFalse(converter.conversionValues().hasNext()); - } - - public void testConversionValues2() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - - - converter.addConversionValue(0); - converter.addConversionValue(1); - - assertEquals(2, converter.conversionValuesSize()); - ListIterator<ConversionValueAnnotation> conversionValues = converter.conversionValues(); - assertTrue(conversionValues.hasNext()); - assertNotNull(conversionValues.next()); - assertNotNull(conversionValues.next()); - assertFalse(conversionValues.hasNext()); - } - - public void testConversionValues3() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - - assertEquals(2, converter.conversionValuesSize()); - ListIterator<ConversionValueAnnotation> conversionValues = converter.conversionValues(); - ConversionValueAnnotation conversionValue = conversionValues.next(); - assertEquals("F", conversionValue.getDataValue()); - assertEquals("Female", conversionValue.getObjectValue()); - conversionValue = conversionValues.next(); - assertEquals("M", conversionValue.getDataValue()); - assertEquals("Male", conversionValue.getObjectValue()); - assertFalse(conversionValues.hasNext()); - } - - public void testAddConversionValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - - converter.addConversionValue(0).setObjectValue("FOO"); - converter.addConversionValue(1); - converter.addConversionValue(0).setDataValue("BAR"); - - assertEquals("BAR", converter.conversionValueAt(0).getDataValue()); - assertNull(converter.conversionValueAt(0).getObjectValue()); - assertEquals("FOO", converter.conversionValueAt(1).getObjectValue()); - assertNull(converter.conversionValueAt(1).getDataValue()); - assertNull(converter.conversionValueAt(2).getDataValue()); - assertNull(converter.conversionValueAt(2).getObjectValue()); - - assertSourceContains("@ObjectTypeConverter(name=\"bar\", conversionValues = {@ConversionValue(dataValue=\"BAR\"),@ConversionValue(objectValue=\"FOO\"), @ConversionValue})", cu); - } - - public void testRemoveConversionValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - converter.addConversionValue(0).setObjectValue("FOO"); - - Iterator<ConversionValueAnnotation> conversionValues = converter.conversionValues(); - assertEquals("FOO", conversionValues.next().getObjectValue()); - assertEquals("Female", conversionValues.next().getObjectValue()); - assertEquals("Male", conversionValues.next().getObjectValue()); - assertFalse(conversionValues.hasNext()); - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(objectValue=\"FOO\"), @ConversionValue(dataValue=\"F\", objectValue = \"Female\"), @ConversionValue(dataValue=\"M\", objectValue = \"Male\")})", cu); - - converter.removeConversionValue(1); - conversionValues = converter.conversionValues(); - assertEquals("FOO", conversionValues.next().getObjectValue()); - assertEquals("Male", conversionValues.next().getObjectValue()); - assertFalse(conversionValues.hasNext()); - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(objectValue=\"FOO\"), @ConversionValue(dataValue=\"M\", objectValue = \"Male\")})", cu); - - converter.removeConversionValue(0); - conversionValues = converter.conversionValues(); - assertEquals("Male", conversionValues.next().getObjectValue()); - assertFalse(conversionValues.hasNext()); - assertSourceContains("@ObjectTypeConverter(conversionValues = @ConversionValue(dataValue=\"M\", objectValue = \"Male\"))", cu); - - - converter.removeConversionValue(0); - assertSourceDoesNotContain("@conversionValues", cu); - assertSourceContains("@ObjectTypeConverter", cu); - } - - public void testMoveConversionValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - converter.addConversionValue(0).setObjectValue("FOO"); - - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(objectValue=\"FOO\"), @ConversionValue(dataValue=\"F\", objectValue = \"Female\"), @ConversionValue(dataValue=\"M\", objectValue = \"Male\")})", cu); - - converter.moveConversionValue(2, 0); - assertEquals("Female", converter.conversionValueAt(0).getObjectValue()); - assertEquals("F", converter.conversionValueAt(0).getDataValue()); - assertEquals("Male", converter.conversionValueAt(1).getObjectValue()); - assertEquals("M", converter.conversionValueAt(1).getDataValue()); - assertEquals("FOO", converter.conversionValueAt(2).getObjectValue()); - assertEquals(null, converter.conversionValueAt(2).getDataValue()); - assertEquals(3, converter.conversionValuesSize()); - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue=\"F\", objectValue = \"Female\"), @ConversionValue(dataValue=\"M\", objectValue = \"Male\"), @ConversionValue(objectValue=\"FOO\")})", cu); - } - - public void testMoveConversionValue2() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ObjectTypeConverterAnnotation converter = (ObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.OBJECT_TYPE_CONVERTER); - converter.addConversionValue(0).setObjectValue("FOO"); - - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(objectValue=\"FOO\"), @ConversionValue(dataValue=\"F\", objectValue = \"Female\"), @ConversionValue(dataValue=\"M\", objectValue = \"Male\")})", cu); - - converter.moveConversionValue(0, 2); - assertEquals("Male", converter.conversionValueAt(0).getObjectValue()); - assertEquals("M", converter.conversionValueAt(0).getDataValue()); - assertEquals("FOO", converter.conversionValueAt(1).getObjectValue()); - assertEquals(null, converter.conversionValueAt(1).getDataValue()); - assertEquals("Female", converter.conversionValueAt(2).getObjectValue()); - assertEquals("F", converter.conversionValueAt(2).getDataValue()); - assertEquals(3, converter.conversionValuesSize()); - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue=\"M\", objectValue = \"Male\"), @ConversionValue(objectValue=\"FOO\"), @ConversionValue(dataValue=\"F\", objectValue = \"Female\")})", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java deleted file mode 100644 index 0c627df76c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.ReadTransformerAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class ReadTransformerAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ReadTransformerAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestReadTransformer() throws Exception { - this.createAnnotationAndMembers("ReadTransformer", "Class transformerClass() default void.class; String method() default \"\""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.READ_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ReadTransformer"); - } - }); - } - - private ICompilationUnit createTestReadTransformerWithTransformerClass() throws Exception { - this.createAnnotationAndMembers("ReadTransformer", "Class transformerClass() default void.class; String method() default \"\""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.READ_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ReadTransformer(transformerClass=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestReadTransformerWithMethod() throws Exception { - this.createAnnotationAndMembers("ReadTransformer", "Class transformerClass() default void.class; String method() default \"\""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.READ_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ReadTransformer(method=\"transformerMethod\")"); - } - }); - } - - public void testReadTransformerAnnotation() throws Exception { - ICompilationUnit cu = this.createTestReadTransformer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER)); - - attributeResource.removeAnnotation(EclipseLinkJPA.READ_TRANSFORMER) ; - assertNull(attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER)); - - attributeResource.addAnnotation(EclipseLinkJPA.READ_TRANSFORMER); - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER)); - } - - public void testGetTransformerClass() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER); - assertEquals("Foo", readTransformer.getTransformerClass()); - } - - public void testSetTransformerClass() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER); - assertEquals("Foo", readTransformer.getTransformerClass()); - - readTransformer.setTransformerClass("Bar"); - assertEquals("Bar", readTransformer.getTransformerClass()); - - assertSourceContains("@ReadTransformer(transformerClass=Bar.class)", cu); - } - - public void testSetTransformerClassNull() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER); - assertEquals("Foo", readTransformer.getTransformerClass()); - - readTransformer.setTransformerClass(null); - assertNull(readTransformer.getTransformerClass()); - - assertSourceContains("@ReadTransformer", cu); - assertSourceDoesNotContain("transformerClass", cu); - } - - public void testGetMethod() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER); - assertEquals("transformerMethod", readTransformer.getMethod()); - } - - public void testSetMethod() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER); - assertEquals("transformerMethod", readTransformer.getMethod()); - - readTransformer.setMethod("foo"); - assertEquals("foo", readTransformer.getMethod()); - - assertSourceContains("@ReadTransformer(method=\"foo\")", cu); - } - - public void testSetMethodNull() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER); - assertEquals("transformerMethod", readTransformer.getMethod()); - - readTransformer.setMethod(null); - assertNull(readTransformer.getMethod()); - - assertSourceContains("@ReadTransformer", cu); - assertSourceDoesNotContain("method", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java deleted file mode 100644 index 6028ac9c26..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.StructConverterAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class StructConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public StructConverterAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestStructConverter() throws Exception { - this.createAnnotationAndMembers("StructConverter", "String name(); String converter()"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.STRUCT_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@StructConverter"); - } - }); - } - - private ICompilationUnit createTestStructConverterWithConverter() throws Exception { - this.createAnnotationAndMembers("StructConverter", "String name(); String converter()"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.STRUCT_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@StructConverter(converter=\"Foo\")"); - } - }); - } - - private ICompilationUnit createTestStructConverterWithName() throws Exception { - this.createAnnotationAndMembers("StructConverter", "String name(); String converter()"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.STRUCT_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@StructConverter(name=\"bar\")"); - } - }); - } - - public void testStructConverterAnnotation() throws Exception { - ICompilationUnit cu = this.createTestStructConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER)); - - attributeResource.removeAnnotation(EclipseLinkJPA.STRUCT_CONVERTER); - assertNull(attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER)); - - attributeResource.addAnnotation(EclipseLinkJPA.STRUCT_CONVERTER); - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER)); - } - - public void testGetConverter() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER); - assertEquals("Foo", converter.getConverter()); - } - - public void testSetConverter() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER); - assertEquals("Foo", converter.getConverter()); - - converter.setConverter("Bar"); - assertEquals("Bar", converter.getConverter()); - - assertSourceContains("@StructConverter(converter=\"Bar\")", cu); - } - - public void testSetConverterNull() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER); - assertEquals("Foo", converter.getConverter()); - - converter.setConverter(null); - assertNull(converter.getConverter()); - - assertSourceContains("@StructConverter", cu); - assertSourceDoesNotContain("converter", cu); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER); - assertEquals("bar", converter.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName("foo"); - assertEquals("foo", converter.getName()); - - assertSourceContains("@StructConverter(name=\"foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName(null); - assertNull(converter.getName()); - - assertSourceContains("@StructConverter", cu); - assertSourceDoesNotContain("name=", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TimeOfDayTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TimeOfDayTests.java deleted file mode 100644 index 71d72d0a1e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TimeOfDayTests.java +++ /dev/null @@ -1,251 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.CacheAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.TimeOfDayAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class TimeOfDayTests extends EclipseLinkJavaResourceModelTestCase { - - public TimeOfDayTests(String name) { - super(name); - } - - private void createTimeOfDayAnnotation() throws Exception { - - this.createAnnotationAndMembers("TimeOfDay", - "int hour() default 0; " + - "int minute() default 0; " + - "int second() default 0; " + - "int millisecond() default 0;"); - } - - private void createCacheAnnotation() throws Exception { - this.createAnnotationAndMembers("Cache", - "CacheType type() default SOFT_WEAK; " + - "int size() default 100; " + - "boolean shared() default true; " + - "int expiry() default -1; " + - "TimeOfDay expiryTimeOfDay() default @TimeOfDay(specified=false); " + - "boolean alwaysRefresh() default false; " + - "boolean refreshOnlyIfNewer() default false; " + - "boolean disableHits() default false; " + - "CacheCoordinationType coordinationType() default SEND_OBJECT_CHANGES;"); - } - - private ICompilationUnit createTestTimeOfDay() throws Exception { - createCacheAnnotation(); - createTimeOfDayAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE, EclipseLinkJPA.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay)"); - } - }); - } - - private ICompilationUnit createTestTimeOfDayWithHour() throws Exception { - createCacheAnnotation(); - createTimeOfDayAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE, EclipseLinkJPA.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay(hour=5))"); - } - }); - } - - private ICompilationUnit createTestTimeOfDayWithMinute() throws Exception { - createCacheAnnotation(); - createTimeOfDayAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE, EclipseLinkJPA.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay(minute=5))"); - } - }); - } - - private ICompilationUnit createTestTimeOfDayWithSecond() throws Exception { - createCacheAnnotation(); - createTimeOfDayAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE, EclipseLinkJPA.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay(second=5))"); - } - }); - } - - private ICompilationUnit createTestTimeOfDayWithMillisecond() throws Exception { - createCacheAnnotation(); - createTimeOfDayAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.CACHE, EclipseLinkJPA.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay(millisecond=5))"); - } - }); - } - - public void testExpiryTimeOfDay() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDay(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - - assertNotNull(timeOfDay); - } - - public void testGetHour() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithHour(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getHour()); - } - - public void testSetHour() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithHour(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getHour()); - - timeOfDay.setHour(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), timeOfDay.getHour()); - - assertSourceContains("@TimeOfDay(hour=80)", cu); - - timeOfDay.setHour(null); - assertNull(timeOfDay.getHour()); - - assertSourceDoesNotContain("(hour=80)", cu); - assertSourceContains("@TimeOfDay", cu); - } - - public void testGetMinute() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithMinute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getMinute()); - } - - public void testSetMinute() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithMinute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getMinute()); - - timeOfDay.setMinute(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), timeOfDay.getMinute()); - - assertSourceContains("@TimeOfDay(minute=80)", cu); - - timeOfDay.setMinute(null); - assertNull(timeOfDay.getMinute()); - - assertSourceDoesNotContain("(minute=80)", cu); - assertSourceContains("@TimeOfDay", cu); - } - - public void testGetSecond() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithSecond(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getSecond()); - } - - public void testSetSecond() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithSecond(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getSecond()); - - timeOfDay.setSecond(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), timeOfDay.getSecond()); - - assertSourceContains("@TimeOfDay(second=80)", cu); - - timeOfDay.setSecond(null); - assertNull(timeOfDay.getSecond()); - - assertSourceDoesNotContain("(second=80)", cu); - assertSourceContains("@TimeOfDay", cu); - } - - public void testGetMillisecond() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithMillisecond(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getMillisecond()); - } - - public void testSetMillisecond() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithMillisecond(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - CacheAnnotation cache = (CacheAnnotation) typeResource.getAnnotation(EclipseLinkJPA.CACHE); - TimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getMillisecond()); - - timeOfDay.setMillisecond(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), timeOfDay.getMillisecond()); - - assertSourceContains("@TimeOfDay(millisecond=80)", cu); - - timeOfDay.setMillisecond(null); - assertNull(timeOfDay.getMillisecond()); - - assertSourceDoesNotContain("(millisecond=80)", cu); - assertSourceContains("@TimeOfDay", cu); - } - - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java deleted file mode 100644 index eecfa1a2ee..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.TransformationAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class TransformationAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public TransformationAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestTransformation() throws Exception { - this.createAnnotationAndMembers("Transformation", "boolean optional() default true;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.TRANSFORMATION); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transformation"); - } - }); - } - - private ICompilationUnit createTestTransformationWithOptional() throws Exception { - this.createAnnotationAndMembers("Transformation", "boolean optional() default true;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.TRANSFORMATION); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transformation(optional=true)"); - } - }); - } - - private ICompilationUnit createTestTransformationWithFetch() throws Exception { - this.createAnnotationAndMembers("Transformation", "boolean optional() default true; FetchType fetch() default FetchType.EAGER;"); - this.createEnumAndMembers(JPA.PACKAGE, "FetchType", "EAGER, LAZY"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.TRANSFORMATION, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transformation(fetch=FetchType.EAGER)"); - } - }); - } - - public void testTransformationAnnotation() throws Exception { - ICompilationUnit cu = this.createTestTransformation(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION)); - - attributeResource.setMappingAnnotation(null); - assertNull(attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION)); - - attributeResource.setMappingAnnotation(EclipseLinkJPA.TRANSFORMATION); - assertNotNull(attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION)); - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION); - assertEquals(Boolean.TRUE, transformation.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION); - assertEquals(Boolean.TRUE, transformation.getOptional()); - - transformation.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, transformation.getOptional()); - - assertSourceContains("@Transformation(optional=false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION); - assertEquals(Boolean.TRUE, transformation.getOptional()); - - transformation.setOptional(null); - assertNull(transformation.getOptional()); - - assertSourceContains("@Transformation", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION); - assertEquals(FetchType.EAGER, transformation.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION); - assertEquals(FetchType.EAGER, transformation.getFetch()); - - transformation.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, transformation.getFetch()); - - assertSourceContains("@Transformation(fetch=LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION); - assertEquals(FetchType.EAGER, transformation.getFetch()); - - transformation.setFetch(null); - assertNull(transformation.getFetch()); - - assertSourceContains("@Transformation", cu); - assertSourceDoesNotContain("fetch", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java deleted file mode 100644 index 50c4ed90f2..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.TypeConverterAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class TypeConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public TypeConverterAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestTypeConverter() throws Exception { - this.createAnnotationAndMembers("TypeConverter", "String name(); Class dataType() default void.class; Class objectType() default void.class "); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TypeConverter"); - } - }); - } - - private ICompilationUnit createTestTypeConverterWithDataType() throws Exception { - this.createAnnotationAndMembers("TypeConverter", "String name(); Class dataType() default void.class; Class objectType() default void.class "); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TypeConverter(dataType=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestTypeConverterWithObjectType() throws Exception { - this.createAnnotationAndMembers("TypeConverter", "String name(); Class dataType() default void.class; Class objectType() default void.class "); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TypeConverter(objectType=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestTypeConverterWithName() throws Exception { - this.createAnnotationAndMembers("TypeConverter", "String name(); Class dataType() default void.class; Class objectType() default void.class "); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TypeConverter(name=\"bar\")"); - } - }); - } - - public void testTypeConverterAnnotation() throws Exception { - ICompilationUnit cu = this.createTestTypeConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER)); - - attributeResource.removeAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertNull(attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER)); - - attributeResource.addAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER)); - } - - public void testGetTypeDataType() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - } - - public void testSetDataType() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType("Bar"); - assertEquals("Bar", converter.getDataType()); - - assertSourceContains("@TypeConverter(dataType=Bar.class)", cu); - } - - public void testSetDataTypeNull() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType(null); - assertNull(converter.getDataType()); - - assertSourceContains("@TypeConverter", cu); - assertSourceDoesNotContain("dataType", cu); - } - - public void testGetTypeObjectType() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - } - - public void testSetObjectType() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType("Bar"); - assertEquals("Bar", converter.getObjectType()); - - assertSourceContains("@TypeConverter(objectType=Bar.class)", cu); - } - - public void testSetObjectTypeNull() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType(null); - assertNull(converter.getObjectType()); - - assertSourceContains("@TypeConverter", cu); - assertSourceDoesNotContain("objectType", cu); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName("foo"); - assertEquals("foo", converter.getName()); - - assertSourceContains("@TypeConverter(name=\"foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName(null); - assertNull(converter.getName()); - - assertSourceContains("@TypeConverter", cu); - assertSourceDoesNotContain("name=", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java deleted file mode 100644 index 1d2fcea9de..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java +++ /dev/null @@ -1,241 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; -import org.eclipse.jpt.eclipselink.core.resource.java.WriteTransformerAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class WriteTransformerAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public WriteTransformerAnnotationTests(String name) { - super(name); - } - - private void createWriteTransformerAnnotation() throws Exception { - this.createAnnotationAndMembers("WriteTransformer", "Class transformerClass() default void.class; String method() default \"\";Column column() default @Column"); - this.createColumnAnnotation(); - } - - private void createColumnAnnotation() throws Exception { - this.createAnnotationAndMembers(JPA.PACKAGE, "Column", - "String name() default \"\"; " + - "boolean unique() default false; " + - "boolean nullable() default true; " + - "boolean insertable() default true; " + - "boolean updatable() default true; " + - "String columnDefinition() default \"\"; " + - "String table() default \"\"; " + - "int length() default 255; " + - "int precision() default 0; " + - "int scale() default 0;"); - } - - private ICompilationUnit createTestWriteTransformer() throws Exception { - createWriteTransformerAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.WRITE_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@WriteTransformer"); - } - }); - } - - private ICompilationUnit createTestWriteTransformerWithTransformerClass() throws Exception { - createWriteTransformerAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.WRITE_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@WriteTransformer(transformerClass=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestWriteTransformerWithMethod() throws Exception { - createWriteTransformerAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.WRITE_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@WriteTransformer(method=\"transformerMethod\")"); - } - }); - } - - private ICompilationUnit createTestWriteTransformerWithColumn() throws Exception { - createWriteTransformerAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(EclipseLinkJPA.WRITE_TRANSFORMER, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@WriteTransformer(column=@Column(name=\"FOO\"))"); - } - }); - } - - - public void testWriteTransformerAnnotation() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER)); - - attributeResource.removeAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER) ; - assertNull(attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER)); - - attributeResource.addAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER)); - } - - public void testGetTransformerClass() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertEquals("Foo", writeTransformer.getTransformerClass()); - } - - public void testSetTransformerClass() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertEquals("Foo", writeTransformer.getTransformerClass()); - - writeTransformer.setTransformerClass("Bar"); - assertEquals("Bar", writeTransformer.getTransformerClass()); - - assertSourceContains("@WriteTransformer(transformerClass=Bar.class)", cu); - } - - public void testSetTransformerClassNull() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertEquals("Foo", writeTransformer.getTransformerClass()); - - writeTransformer.setTransformerClass(null); - assertNull(writeTransformer.getTransformerClass()); - - assertSourceContains("@WriteTransformer", cu); - assertSourceDoesNotContain("transformerClass", cu); - } - - public void testGetMethod() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertEquals("transformerMethod", writeTransformer.getMethod()); - } - - public void testSetMethod() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertEquals("transformerMethod", writeTransformer.getMethod()); - - writeTransformer.setMethod("foo"); - assertEquals("foo", writeTransformer.getMethod()); - - assertSourceContains("@WriteTransformer(method=\"foo\")", cu); - } - - public void testSetMethodNull() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertEquals("transformerMethod", writeTransformer.getMethod()); - - writeTransformer.setMethod(null); - assertNull(writeTransformer.getMethod()); - - assertSourceContains("@WriteTransformer", cu); - assertSourceDoesNotContain("method", cu); - } - - - public void testGetColumn() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertNotNull(writeTransformer.getColumn()); - assertEquals("FOO", writeTransformer.getColumn().getName()); - } - - public void testAddColumn() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertNull(writeTransformer.getColumn()); - - writeTransformer.addColumn(); - - assertNotNull(writeTransformer.getColumn()); - assertSourceContains("@WriteTransformer(method=\"transformerMethod\", column = @Column)", cu); - - writeTransformer.getColumn().setName("BAR"); - assertSourceContains("@WriteTransformer(method=\"transformerMethod\", column = @Column(name=\"BAR\"))", cu); - - } - - public void testRemoveColumn() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER); - assertNotNull(writeTransformer.getColumn()); - assertEquals("FOO", writeTransformer.getColumn().getName()); - - writeTransformer.removeColumn(); - assertNull(writeTransformer.getColumn()); - - assertSourceContains("@WriteTransformer", cu); - assertSourceDoesNotContain("column", cu); - } - - public void getNonNullColumn() throws Exception { - - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/orm/EclipseLinkOrmResourceModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/orm/EclipseLinkOrmResourceModelTests.java deleted file mode 100644 index 3884158bf5..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/orm/EclipseLinkOrmResourceModelTests.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.orm; - -import junit.framework.TestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; -import org.eclipse.jpt.eclipselink.core.resource.elorm.EclipseLinkOrmArtifactEdit; -import org.eclipse.jpt.eclipselink.core.resource.elorm.EclipseLinkOrmFactory; -import org.eclipse.jpt.eclipselink.core.resource.elorm.EclipseLinkOrmResource; -import org.eclipse.jpt.eclipselink.core.resource.elorm.XmlEntityMappings; - -public class EclipseLinkOrmResourceModelTests extends TestCase -{ - static final String BASE_PROJECT_NAME = EclipseLinkOrmResourceModelTests.class.getSimpleName(); - - TestJpaProject jpaProject; - - - public EclipseLinkOrmResourceModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.jpaProject = TestJpaProject.buildJpaProject(BASE_PROJECT_NAME, false); // false = no auto-build - - EclipseLinkOrmArtifactEdit ae = - EclipseLinkOrmArtifactEdit.getArtifactEditForWrite(this.jpaProject.getProject()); - EclipseLinkOrmResource resource = - ae.getResource(JptEclipseLinkCorePlugin.getDefaultEclipseLinkOrmXmlDeploymentURI(this.jpaProject.getProject())); - - // 202811 - do not add content if it is already present - if (resource.getEntityMappings() == null) { - XmlEntityMappings entityMappings = EclipseLinkOrmFactory.eINSTANCE.createXmlEntityMappings(); - entityMappings.setVersion("1.0"); - resource.getContents().add(entityMappings); - ae.save(null); - } - - ae.dispose(); - } - - @Override - protected void tearDown() throws Exception { - this.jpaProject.getProject().delete(true, true, null); - this.jpaProject = null; - super.tearDown(); - } - - public void testModelLoad() { - EclipseLinkOrmArtifactEdit artifactEdit = - EclipseLinkOrmArtifactEdit.getArtifactEditForRead(this.jpaProject.getProject()); - assertNotNull(artifactEdit); - EclipseLinkOrmResource resource = artifactEdit.getResource("META-INF/eclipselink-orm.xml"); - assertNotNull(resource); - artifactEdit.dispose(); - } - - public void testModelLoad2() { - EclipseLinkOrmArtifactEdit artifactEdit = - EclipseLinkOrmArtifactEdit.getArtifactEditForRead(this.jpaProject.getProject()); - assertNotNull(artifactEdit); - EclipseLinkOrmResource resource = artifactEdit.getResource("META-INF/eclipselink-orm.xml"); - assertNotNull(resource); - artifactEdit.dispose(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/JptEclipseLinkCoreSchemaGenerationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/JptEclipseLinkCoreSchemaGenerationTests.java deleted file mode 100644 index c475f9f512..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/JptEclipseLinkCoreSchemaGenerationTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.schema.generation; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkCoreSchemaGenerationTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreSchemaGenerationTests.class.getPackage().getName()); - - suite.addTestSuite(SchemaGenerationValueModelTests.class); - suite.addTestSuite(SchemaGenerationBasicAdapterTests.class); - suite.addTestSuite(SchemaGenerationAdapterTests.class); - - return suite; - } - - private JptEclipseLinkCoreSchemaGenerationTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationAdapterTests.java deleted file mode 100644 index cccf09a962..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationAdapterTests.java +++ /dev/null @@ -1,265 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.schema.generation; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.context.persistence.GenericProperty; -import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.DdlGenerationType; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.EclipseLinkSchemaGeneration; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.OutputMode; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.SchemaGeneration; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * Tests the update of OutputMode model object by the SchemaGeneration adapter - * when the PersistenceUnit changes. - */ -public class SchemaGenerationAdapterTests extends PersistenceUnitTestCase -{ - private SchemaGeneration schemaGeneration; - - public static final String DDL_GENERATION_TYPE_KEY = SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE; - public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE = DdlGenerationType.drop_and_create_tables; - public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE_2 = DdlGenerationType.none; - - public static final String OUTPUT_MODE_KEY = SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE; - public static final OutputMode OUTPUT_MODE_TEST_VALUE = OutputMode.sql_script; - public static final OutputMode OUTPUT_MODE_TEST_VALUE_2 = OutputMode.database; - - private static final String CREATE_FILE_NAME_KEY = SchemaGeneration.ECLIPSELINK_CREATE_FILE_NAME; - private static final String CREATE_FILE_NAME_TEST_VALUE = "create-file-name.test"; - private static final String CREATE_FILE_NAME_TEST_VALUE_2 = "create-file-name-2.test"; - - private static final String DROP_FILE_NAME_KEY = SchemaGeneration.ECLIPSELINK_DROP_FILE_NAME; - private static final String DROP_FILE_NAME_TEST_VALUE = "drop-file-name.test"; - private static final String DROP_FILE_NAME_TEST_VALUE_2 = "drop-file-name-2.test"; - - private static final String APPLICATION_LOCATION_KEY = SchemaGeneration.ECLIPSELINK_APPLICATION_LOCATION; - private static final String APPLICATION_LOCATION_TEST_VALUE = "C:/temp"; - private static final String APPLICATION_LOCATION_TEST_VALUE_2 = "C:/tmp"; - - public SchemaGenerationAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.schemaGeneration = this.persistenceUnitProperties.getSchemaGeneration(); - - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.OUTPUT_MODE_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.CREATE_FILE_NAME_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.DROP_FILE_NAME_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.APPLICATION_LOCATION_PROPERTY, propertyChangeListener); - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. Cannot use - * Property Holder to initialize because it is not created yet - */ - @Override - protected void populatePu() { - this.propertiesTotal = 9; - this.modelPropertiesSizeOriginal = 5; - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitPut("property.0", "value.0"); - this.persistenceUnitPut(OUTPUT_MODE_KEY, this.getEclipseLinkStringValueOf(OUTPUT_MODE_TEST_VALUE)); - this.persistenceUnitPut("property.2", "value.2"); - this.persistenceUnitPut("property.3", "value.3"); - this.persistenceUnitPut("property.4", "value.4"); - this.persistenceUnitPut(DDL_GENERATION_TYPE_KEY, this.getEclipseLinkStringValueOf(DDL_GENERATION_TYPE_TEST_VALUE)); - this.persistenceUnitPut(CREATE_FILE_NAME_KEY, CREATE_FILE_NAME_TEST_VALUE); - this.persistenceUnitPut(DROP_FILE_NAME_KEY, DROP_FILE_NAME_TEST_VALUE); - this.persistenceUnitPut(APPLICATION_LOCATION_KEY, APPLICATION_LOCATION_TEST_VALUE); - return; - } - - public void testHasListeners() throws Exception { - ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter = (ListAspectAdapter<PersistenceUnit, Property>) ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertiesAdapter(); - GenericProperty outputModeProperty = (GenericProperty) this.persistenceUnit().getProperty(OUTPUT_MODE_KEY); - GenericProperty ddlGenTypeProperty = (GenericProperty) this.persistenceUnit().getProperty(DDL_GENERATION_TYPE_KEY); - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - assertTrue(ddlGenTypeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.OUTPUT_MODE_PROPERTY); - this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY); - this.verifyHasListeners(propertyListAdapter); - - EclipseLinkSchemaGeneration schemaGen = (EclipseLinkSchemaGeneration) this.schemaGeneration; - PersistenceUnitPropertyListListener propertyListListener = schemaGen.propertyListListener(); - propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener); - this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.OUTPUT_MODE_PROPERTY); - this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY); - } - - // ********** CreateFileName ********** - /** - * Tests the update of CreateFileName property by the SchemaGeneration - * adapter when the PU or the model changes. - */ - public void testSetCreateFileName() throws Exception { - this.verifyModelInitialized( - CREATE_FILE_NAME_KEY, - CREATE_FILE_NAME_TEST_VALUE); - this.verifySetProperty( - CREATE_FILE_NAME_KEY, - CREATE_FILE_NAME_TEST_VALUE, - CREATE_FILE_NAME_TEST_VALUE_2); - } - - public void testAddRemoveCreateFileName() throws Exception { - this.verifyAddRemoveProperty( - CREATE_FILE_NAME_KEY, - CREATE_FILE_NAME_TEST_VALUE, - CREATE_FILE_NAME_TEST_VALUE_2); - } - - // ********** DropFileName ********** - /** - * Tests the update of DropFileName property by the SchemaGeneration adapter - * when the PU or the model changes. - */ - public void testSetDropFileName() throws Exception { - this.verifyModelInitialized( - DROP_FILE_NAME_KEY, - DROP_FILE_NAME_TEST_VALUE); - this.verifySetProperty( - DROP_FILE_NAME_KEY, - DROP_FILE_NAME_TEST_VALUE, - DROP_FILE_NAME_TEST_VALUE_2); - } - - public void testAddRemoveDropFileName() throws Exception { - this.verifyAddRemoveProperty( - DROP_FILE_NAME_KEY, - DROP_FILE_NAME_TEST_VALUE, - DROP_FILE_NAME_TEST_VALUE_2); - } - - // ********** ApplicationLocation ********** - /** - * Tests the update of ApplicationLocation property by the SchemaGeneration - * adapter when the PU or the model changes. - */ - public void testSetApplicationLocation() throws Exception { - this.verifyModelInitialized( - APPLICATION_LOCATION_KEY, - APPLICATION_LOCATION_TEST_VALUE); - this.verifySetProperty( - APPLICATION_LOCATION_KEY, - APPLICATION_LOCATION_TEST_VALUE, - APPLICATION_LOCATION_TEST_VALUE_2); - } - - public void testAddRemoveApplicationLocation() throws Exception { - this.verifyAddRemoveProperty( - APPLICATION_LOCATION_KEY, - APPLICATION_LOCATION_TEST_VALUE, - APPLICATION_LOCATION_TEST_VALUE_2); - } - - // ********** OutputMode ********** - /** - * Tests the update of OutputMode property by the SchemaGeneration adapter - * when the PU or the model changes. - */ - public void testSetOutputMode() throws Exception { - this.verifyModelInitialized( - OUTPUT_MODE_KEY, - OUTPUT_MODE_TEST_VALUE); - this.verifySetProperty( - OUTPUT_MODE_KEY, - OUTPUT_MODE_TEST_VALUE, - OUTPUT_MODE_TEST_VALUE_2); - } - - public void testAddRemoveOutputMode() throws Exception { - this.verifyAddRemoveProperty( - OUTPUT_MODE_KEY, - OUTPUT_MODE_TEST_VALUE, - OUTPUT_MODE_TEST_VALUE_2); - } - - // ********** DdlGenerationType ********** - /** - * Tests the update of DdlGenerationType property by the SchemaGeneration - * adapter when the PU or the model changes. - */ - public void testSetDdlGenerationType() throws Exception { - this.verifyModelInitialized( - DDL_GENERATION_TYPE_KEY, - DDL_GENERATION_TYPE_TEST_VALUE); - this.verifySetProperty( - DDL_GENERATION_TYPE_KEY, - DDL_GENERATION_TYPE_TEST_VALUE, - DDL_GENERATION_TYPE_TEST_VALUE_2); - } - - public void testAddRemoveDdlGenerationType() throws Exception { - this.verifyAddRemoveProperty( - DDL_GENERATION_TYPE_KEY, - DDL_GENERATION_TYPE_TEST_VALUE, - DDL_GENERATION_TYPE_TEST_VALUE_2); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws NoSuchFieldException { - if (propertyName.equals(SchemaGeneration.OUTPUT_MODE_PROPERTY)) - this.schemaGeneration.setOutputMode((OutputMode) newValue); - // else if( propertyName.equals( Caching.CACHE_SIZE_PROPERTY)) - // TODO - else if (propertyName.equals(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY)) - this.schemaGeneration.setDdlGenerationType((DdlGenerationType) newValue); - else if (propertyName.equals(SchemaGeneration.APPLICATION_LOCATION_PROPERTY)) - this.schemaGeneration.setApplicationLocation((String) newValue); - else if (propertyName.equals(SchemaGeneration.CREATE_FILE_NAME_PROPERTY)) - this.schemaGeneration.setCreateFileName((String) newValue); - else if (propertyName.equals(SchemaGeneration.DROP_FILE_NAME_PROPERTY)) - this.schemaGeneration.setDropFileName((String) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(SchemaGeneration.OUTPUT_MODE_PROPERTY)) - modelValue = this.schemaGeneration.getOutputMode(); - else if (propertyName.equals(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY)) - modelValue = this.schemaGeneration.getDdlGenerationType(); - else if (propertyName.equals(SchemaGeneration.APPLICATION_LOCATION_PROPERTY)) - modelValue = this.schemaGeneration.getApplicationLocation(); - else if (propertyName.equals(SchemaGeneration.CREATE_FILE_NAME_PROPERTY)) - modelValue = this.schemaGeneration.getCreateFileName(); - else if (propertyName.equals(SchemaGeneration.DROP_FILE_NAME_PROPERTY)) - modelValue = this.schemaGeneration.getDropFileName(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - protected PersistenceUnitProperties model() { - return this.schemaGeneration; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationBasicAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationBasicAdapterTests.java deleted file mode 100644 index 2c13374374..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationBasicAdapterTests.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.schema.generation; - -import java.util.ListIterator; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.context.persistence.GenericProperty; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.DdlGenerationType; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.EclipseLinkSchemaGeneration; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.OutputMode; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.SchemaGeneration; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; - -/** - * Tests the update of OutputMode model object by the SchemaGeneration adapter - * when the PersistenceUnit changes. - */ -public class SchemaGenerationBasicAdapterTests extends PersistenceUnitTestCase -{ - private SchemaGeneration schemaGeneration; - - public static final String outputModeKey = SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE; - public static final String ddlGenTypeKey = SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE; - - public static final OutputMode OUTPUT_MODE_TEST_VALUE = OutputMode.sql_script; - public static final OutputMode OUTPUT_MODE_TEST_VALUE_2 = OutputMode.database; - - public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE = DdlGenerationType.drop_and_create_tables; - public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE_2 = DdlGenerationType.none; - - public SchemaGenerationBasicAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - this.schemaGeneration = this.persistenceUnitProperties.getSchemaGeneration(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.OUTPUT_MODE_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, propertyChangeListener); - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. Cannot use - * Property Holder to initialize because it is not created yet - */ - @Override - protected void populatePu() { - this.propertiesTotal = 6; - this.modelPropertiesSizeOriginal = 2; - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitPut("property.0", "value.0"); - this.persistenceUnitPut(outputModeKey, this.getEclipseLinkStringValueOf(OUTPUT_MODE_TEST_VALUE)); - this.persistenceUnitPut("property.2", "value.2"); - this.persistenceUnitPut("property.3", "value.3"); - this.persistenceUnitPut("property.4", "value.4"); - this.persistenceUnitPut(ddlGenTypeKey, this.getEclipseLinkStringValueOf(DDL_GENERATION_TYPE_TEST_VALUE)); - return; - } - - /** ****** test methods ******* */ - public void testHasListeners() throws Exception { - ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter = - (ListAspectAdapter<PersistenceUnit, Property>) this.buildPropertiesAdapter(this.subjectHolder); - assertFalse(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - GenericProperty outputModeProperty = (GenericProperty) this.persistenceUnit().getProperty(outputModeKey); - GenericProperty ddlGenTypeProperty = (GenericProperty) this.persistenceUnit().getProperty(ddlGenTypeKey); - assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - - ListValueModel<Property> propertyListAdapter = - new ItemPropertyListValueModelAdapter<Property>(propertiesAdapter, Property.VALUE_PROPERTY, Property.NAME_PROPERTY); - assertFalse(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - assertTrue(ddlGenTypeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.OUTPUT_MODE_PROPERTY); - this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY); - this.verifyHasNoListeners(propertyListAdapter); - - PersistenceUnitPropertyListListener propertyListListener = - new PersistenceUnitPropertyListListener(this.schemaGeneration); - propertyListAdapter.addListChangeListener(ListValueModel.LIST_VALUES, propertyListListener); - assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - assertTrue(ddlGenTypeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - this.verifyHasListeners(propertyListAdapter); - - propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener); - assertFalse(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - assertTrue(ddlGenTypeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY)); - this.verifyHasNoListeners(propertyListAdapter); - } - - /** - * Tests the update of OutputMode property by the SchemaGeneration adapter - * when the PU changes. - */ - public void testOutputModeUpdate() throws Exception { - ListValueModel<Property> propertiesAdapter = this.buildPropertiesAdapter(this.subjectHolder); - ListValueModel<Property> propertyListAdapter = new ItemPropertyListValueModelAdapter<Property>(propertiesAdapter, Property.VALUE_PROPERTY); - PersistenceUnitPropertyListListener propertyListListener = ((EclipseLinkSchemaGeneration) this.schemaGeneration).propertyListListener(); - propertyListAdapter.addListChangeListener(ListValueModel.LIST_VALUES, propertyListListener); - - this.verifyHasListeners(propertyListAdapter); - this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.OUTPUT_MODE_PROPERTY); - - // Basic - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - assertTrue(schemaGeneration.itemIsProperty(this.persistenceUnit().getProperty(outputModeKey))); - assertEquals(OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode()); - - // Replace - this.persistenceUnitPut(outputModeKey, OUTPUT_MODE_TEST_VALUE_2); - this.verifyPutEvent(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE_2, this.schemaGeneration.getOutputMode()); - - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.persistenceUnit().removeProperty(outputModeKey); - assertFalse(this.persistenceUnit().containsProperty(outputModeKey)); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - assertNotNull(this.propertyChangedEvent); - assertNull(this.propertyChangedEvent.getNewValue()); - - // Add original OutputMode - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitPut(outputModeKey, OUTPUT_MODE_TEST_VALUE); - this.verifyPutEvent(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode()); - - // Replace again - this.persistenceUnitPut(outputModeKey, OUTPUT_MODE_TEST_VALUE_2); - this.verifyPutEvent(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE_2, this.schemaGeneration.getOutputMode()); - - // Replace by setting model object - this.clearEvent(); - this.schemaGeneration.setOutputMode(OUTPUT_MODE_TEST_VALUE); - this.verifyPutEvent(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode()); - } - - // ****** convenience methods ******* - protected PersistenceUnitProperties model() { - return this.schemaGeneration; - } - - private ListValueModel<Property> buildPropertiesAdapter(PropertyValueModel<PersistenceUnit> subjectHolder) { - return new ListAspectAdapter<PersistenceUnit, Property>(subjectHolder, PersistenceUnit.PROPERTIES_LIST) { - @Override - protected ListIterator<Property> listIterator_() { - return this.subject.properties(); - } - - @Override - protected int size_() { - return this.subject.propertiesSize(); - } - }; - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationValueModelTests.java deleted file mode 100644 index db8ceb2f34..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationValueModelTests.java +++ /dev/null @@ -1,232 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.schema.generation; - -import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.DdlGenerationType; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.OutputMode; -import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.SchemaGeneration; -import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * SchemaGenerationValueModelTests - * - * Tests the PropertyValueModel of SchemaGeneration model and the update of the - * PersistenceUnit. - */ -public class SchemaGenerationValueModelTests extends PersistenceUnitTestCase -{ - private SchemaGeneration schemaGen; - private PropertyValueModel<SchemaGeneration> schemaGenHolder; - - private WritablePropertyValueModel<DdlGenerationType> ddlGenerationTypeHolder; - private PropertyChangeEvent ddlGenerationTypeEvent; - - private WritablePropertyValueModel<OutputMode> outputModeHolder; - private PropertyChangeEvent outputModeEvent; - - public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE = DdlGenerationType.drop_and_create_tables; - public static final OutputMode OUTPUT_MODE_TEST_VALUE = OutputMode.sql_script; - - public SchemaGenerationValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.schemaGen = this.persistenceUnitProperties.getSchemaGeneration(); // Subject - this.schemaGenHolder = new SimplePropertyValueModel<SchemaGeneration>(this.schemaGen); - - this.ddlGenerationTypeHolder = this.buildDdlGenerationTypeAA(this.schemaGenHolder); - PropertyChangeListener ddlGenerationTypeListener = this.buildDdlGenerationTypeChangeListener(); - this.ddlGenerationTypeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, ddlGenerationTypeListener); - this.ddlGenerationTypeEvent = null; - - this.outputModeHolder = this.buildOutputModeAA(this.schemaGenHolder); - PropertyChangeListener outputModeListener = this.buildOutputModeChangeListener(); - this.outputModeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, outputModeListener); - this.outputModeEvent = null; - } - - /** - * Initializes directly the PU properties before testing. Cannot use - * Property Holder to initialize because it is not created yet - */ - @Override - protected void populatePu() { - this.persistenceUnitPut( - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE, - DDL_GENERATION_TYPE_TEST_VALUE); - this.persistenceUnitPut( - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE, - OUTPUT_MODE_TEST_VALUE); - return; - } - - protected PersistenceUnitProperties model() { - return this.schemaGen; - } - - /** ****** DdlGenerationType ******* */ - private WritablePropertyValueModel<DdlGenerationType> buildDdlGenerationTypeAA(PropertyValueModel<SchemaGeneration> subjectHolder) { - return new PropertyAspectAdapter<SchemaGeneration, DdlGenerationType>(subjectHolder, SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY) { - @Override - protected DdlGenerationType buildValue_() { - return this.subject.getDdlGenerationType(); - } - - @Override - protected void setValue_(DdlGenerationType enumValue) { - this.subject.setDdlGenerationType(enumValue); - } - }; - } - - private PropertyChangeListener buildDdlGenerationTypeChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - SchemaGenerationValueModelTests.this.ddlGenerationTypeEvent = e; - } - }; - } - - /** ****** OutputMode ******* */ - private WritablePropertyValueModel<OutputMode> buildOutputModeAA(PropertyValueModel<SchemaGeneration> subjectHolder) { - return new PropertyAspectAdapter<SchemaGeneration, OutputMode>(subjectHolder, SchemaGeneration.OUTPUT_MODE_PROPERTY) { - @Override - protected OutputMode buildValue_() { - return this.subject.getOutputMode(); - } - - @Override - protected void setValue_(OutputMode enumValue) { - this.subject.setOutputMode(enumValue); - } - }; - } - - private PropertyChangeListener buildOutputModeChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - SchemaGenerationValueModelTests.this.outputModeEvent = e; - } - }; - } - - public void testValue() { - /** ****** DdlGenerationType ******* */ - this.verifyDdlGenerationTypeAAValue(DDL_GENERATION_TYPE_TEST_VALUE); - assertEquals( - SchemaGeneration.DEFAULT_SCHEMA_GENERATION_DDL_GENERATION_TYPE, - this.schemaGen.getDefaultDdlGenerationType()); - /** ****** OutputMode ******* */ - this.verifyOutputModeAAValue(OUTPUT_MODE_TEST_VALUE); - assertEquals( - SchemaGeneration.DEFAULT_SCHEMA_GENERATION_OUTPUT_MODE, - this.schemaGen.getDefaultOutputMode()); - } - - public void testSetValue() throws Exception { - /** ****** DdlGenerationType ******* */ - this.ddlGenerationTypeEvent = null; - this.verifyHasListeners(this.ddlGenerationTypeHolder, PropertyValueModel.VALUE); - DdlGenerationType newDdlGenerationType = DdlGenerationType.create_tables; - // Modify the persistenceUnit directly - this.subject.putProperty( - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE, - this.getEclipseLinkStringValueOf(newDdlGenerationType), - false); - this.verifyDdlGenerationTypeAAValue(newDdlGenerationType); - assertNotNull(this.ddlGenerationTypeEvent); - - /** ****** OutputMode ******* */ - this.outputModeEvent = null; - this.verifyHasListeners(this.outputModeHolder, PropertyValueModel.VALUE); - OutputMode newOutputMode = OutputMode.database; - // Modify the property holder - this.outputModeHolder.setValue(newOutputMode); - this.verifyOutputModeAAValue(newOutputMode); - assertNotNull(this.outputModeEvent); - } - - public void testSetNullValue() { - /** ****** DdlGenerationType ******* */ - this.ddlGenerationTypeEvent = null; - // Setting the persistenceUnit directly - this.subject.putProperty(SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE, null, false); - this.ddlGenerationTypeHolder.setValue(null); - // testing Holder - this.verifyDdlGenerationTypeAAValue(null); - assertNotNull(this.ddlGenerationTypeEvent); - // testing PU properties - boolean containsDdlGenerationTypeProperty = - this.persistenceUnit().containsProperty(SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE); - assertFalse(containsDdlGenerationTypeProperty); - - /** ****** OutputMode ******* */ - this.outputModeEvent = null; - // Setting the property holder - this.outputModeHolder.setValue(null); - // testing Holder - this.verifyOutputModeAAValue(null); - assertNotNull(this.outputModeEvent); - // testing PU properties - boolean containsOutputModeProperty = - this.persistenceUnit().containsProperty(SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE); - assertFalse(containsOutputModeProperty); - } - - /** ****** convenience methods ******* */ - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifyDdlGenerationTypeAAValue(DdlGenerationType testValue) { - this.verifyAAValue( - testValue, - this.schemaGen.getDdlGenerationType(), - this.ddlGenerationTypeHolder, - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE); - } - - /** - * Performs three value tests:<br> - * 1. subject value<br> - * 2. aspect adapter value<br> - * 3. persistenceUnit property value<br> - */ - protected void verifyOutputModeAAValue(OutputMode testValue) { - this.verifyAAValue( - testValue, - this.schemaGen.getOutputMode(), - this.outputModeHolder, - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} |