diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org')
15 files changed, 0 insertions, 3189 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 4f933c4094..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java +++ /dev/null @@ -1,40 +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 junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.jpt.eclipselink.core.tests.internal.caching.JptEclipseLinkCoreCachingTests; -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.schema.generation.JptEclipseLinkCoreSchemaGenerationTests; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkCoreTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreTests.class.getPackage().getName()); - - suite.addTest(JptEclipseLinkCoreLoggingTests.suite()); - suite.addTest(JptEclipseLinkCoreCustomizationTests.suite()); - suite.addTest(JptEclipseLinkCoreCachingTests.suite()); - suite.addTest(JptEclipseLinkCoreSchemaGenerationTests.suite()); - - return suite; - } - - 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 510054f599..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/PersistenceUnitTestCase.java +++ /dev/null @@ -1,311 +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.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(); - - /** - * 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; - - /** - * 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 abstract void verifyPutProperty(String propertyName, Object expectedValue) 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) { - if (key == null) { - throw new IllegalArgumentException("EclipseLink Key cannot be null"); - } - if (value == null) - this.putNullProperty(key); - else - this.putProperty_(key, value); - } - - private void putProperty_(String elKey, Object value) { - this.clearEvent(); - this.persistenceUnit().putProperty(elKey, this.getEclipseLinkStringValueOf(value), false); - } - - 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()); - } - - // ****** verify methods ******* - /** - * 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. - */ - protected void verifyModelInitialized(Object modelValue, String elKey, Object expectedValue) { - Property property = this.persistenceUnit().getProperty(elKey); - assertTrue("model.itemIsProperty() is false: ", model().itemIsProperty(property)); - - assertEquals("PersistenceUnit not populated - populatedPu()", this.getEclipseLinkStringValueOf(expectedValue), property.getValue()); - assertEquals("Model not initialized - model.initializeProperties()", 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 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.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 propertyName, String key, Object testValue1, Object testValue2) throws Exception { - ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter(); - - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - assertTrue("persistenceUnit.properties doesn't contains: " + key, this.persistenceUnit().containsProperty(key)); - this.persistenceUnit().removeProperty(key); - assertFalse(this.persistenceUnit().containsProperty(key)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutProperty(propertyName, null); - - // Add original CacheTypeDefault - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitPut(key, testValue1); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutProperty(propertyName, testValue1); - - // Replace - this.persistenceUnitPut(key, testValue2); - assertEquals(this.propertiesTotal, propertyListAdapter.size()); - this.verifyPutProperty(propertyName, testValue2); - } - - protected void verifyPutProperty(String propertyName, Object value, Object expectedValue) { - this.verifyEvent(propertyName); - this.verifyEventValue(value, 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 - assertEquals("Multiple Event Received.", 1, this.propertyChangedEventCount); - } - - 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)); - } -} 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 b098cabc2d..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java +++ /dev/null @@ -1,459 +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.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.event.PropertyChangeEvent; -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); - } - }; - } - - private PropertyChangeListener buildPropertyChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - CachingAdapterTests.this.propertyChangedEvent = event; - CachingAdapterTests.this.propertyChangedEventCount++; - } - - @Override - public String toString() { - return "Caching listener"; - } - }; - } - - @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); - - // try to add it again - this.clearEvent(); - this.caching.addEntity(ENTITY_TEST_2); - // verify event received - assertNull("Event was Fired.", this.entitiesEvent); - - // 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( - this.caching.getCacheTypeDefault(), - CACHE_TYPE_DEFAULT_KEY, - CACHE_TYPE_DEFAULT_TEST_VALUE); - this.verifySetProperty( - Caching.CACHE_TYPE_DEFAULT_PROPERTY, - CACHE_TYPE_DEFAULT_KEY, - CACHE_TYPE_DEFAULT_TEST_VALUE, - CACHE_TYPE_DEFAULT_TEST_VALUE_2); - } - - public void testAddRemoveCacheTypeDefault() throws Exception { - this.verifyAddRemoveProperty( - Caching.CACHE_TYPE_DEFAULT_PROPERTY, - 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( - this.caching.getCacheSizeDefault(), - CACHE_SIZE_DEFAULT_KEY, - CACHE_SIZE_DEFAULT_TEST_VALUE); - this.verifySetProperty( - Caching.CACHE_SIZE_DEFAULT_PROPERTY, - CACHE_SIZE_DEFAULT_KEY, - CACHE_SIZE_DEFAULT_TEST_VALUE, - CACHE_SIZE_DEFAULT_TEST_VALUE_2); - } - - public void testAddRemoveCacheSizeDefault() throws Exception { - this.verifyAddRemoveProperty( - Caching.CACHE_SIZE_DEFAULT_PROPERTY, - CACHE_SIZE_DEFAULT_KEY, - CACHE_SIZE_DEFAULT_TEST_VALUE, - CACHE_SIZE_DEFAULT_TEST_VALUE_2); - } - - // ********** SharedCacheDefault ********** - public void testSetSharedCacheDefault() throws Exception { - this.verifyModelInitialized( - this.caching.getSharedCacheDefault(), - SHARED_CACHE_DEFAULT_KEY, - SHARED_CACHE_DEFAULT_TEST_VALUE); - this.verifySetProperty(Caching.SHARED_CACHE_DEFAULT_PROPERTY, - SHARED_CACHE_DEFAULT_KEY, - SHARED_CACHE_DEFAULT_TEST_VALUE, - SHARED_CACHE_DEFAULT_TEST_VALUE_2); - } - - public void testAddRemoveSharedCacheDefault() throws Exception { - this.verifyAddRemoveProperty( - Caching.SHARED_CACHE_DEFAULT_PROPERTY, - 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( - this.caching.getCacheType(ENTITY_TEST), - 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( - this.caching.getCacheSize(ENTITY_TEST), - 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( - this.caching.getSharedCache(ENTITY_TEST), - 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); - } - } - - @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 void verifyPutProperty(String propertyName, Object expectedValue) throws NoSuchFieldException { - if (propertyName.equals(Caching.CACHE_TYPE_DEFAULT_PROPERTY)) - this.verifyPutProperty(propertyName, this.caching.getCacheTypeDefault(), expectedValue); - else if (propertyName.equals(Caching.CACHE_SIZE_DEFAULT_PROPERTY)) - this.verifyPutProperty(propertyName, this.caching.getCacheSizeDefault(), expectedValue); - else if (propertyName.equals(Caching.SHARED_CACHE_DEFAULT_PROPERTY)) - this.verifyPutProperty(propertyName, this.caching.getSharedCacheDefault(), expectedValue); - else - this.throwMissingDefinition("verifyPutProperty", propertyName); - } -} 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 62a60184ee..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingValueModelTests.java +++ /dev/null @@ -1,395 +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 ******* */ - this.verifyCacheTypeAAValue(CACHE_TYPE_TEST_VALUE); - assertEquals(Caching.DEFAULT_CACHE_TYPE, this.caching.getDefaultCacheType()); - /** ****** SharedCache ******* */ - this.verifySharedCacheAAValue(SHARED_CACHE_TEST_VALUE); - assertEquals(Caching.DEFAULT_SHARED_CACHE, 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); - } - - - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - 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/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 39738e7268..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/CustomizationAdapterTests.java +++ /dev/null @@ -1,483 +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.customization; - -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.event.PropertyChangeEvent; -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; - - 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 = "session.customizer.test"; - private static final String SESSION_CUSTOMIZER_TEST_VALUE_2 = "session.customizer-2.test"; - - 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.SESSION_CUSTOMIZER_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_PROPERTY, propertyChangeListener); - - this.customization.addPropertyChangeListener(Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY, propertyChangeListener); - - 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 PropertyChangeListener buildPropertyChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - CustomizationAdapterTests.this.propertyChangedEvent = event; - CustomizationAdapterTests.this.propertyChangedEventCount++; - } - - @Override - public String toString() { - return "Customization listener"; - } - }; - } - - @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.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); - - // try to add it again - this.clearEvent(); - this.customization.addEntity(ENTITY_TEST_2); - // verify event received - assertNull("Event was Fired.", this.entitiesEvent); - - // 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); - } - - // ********** 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( - this.customization.getThrowExceptions(), - THROW_EXCEPTIONS_KEY, - THROW_EXCEPTIONS_TEST_VALUE); - this.verifySetProperty(Customization.THROW_EXCEPTIONS_PROPERTY, - THROW_EXCEPTIONS_KEY, - THROW_EXCEPTIONS_TEST_VALUE, - THROW_EXCEPTIONS_TEST_VALUE_2); - } - - public void testAddRemoveThrowExceptions() throws Exception { - this.verifyAddRemoveProperty( - Customization.THROW_EXCEPTIONS_PROPERTY, - THROW_EXCEPTIONS_KEY, - THROW_EXCEPTIONS_TEST_VALUE, - THROW_EXCEPTIONS_TEST_VALUE_2); - } - - // ********** WeavingLazy tests ********** - public void testSetWeavingLazy() throws Exception { - this.verifyModelInitialized( - this.customization.getWeavingLazy(), - WEAVING_LAZY_KEY, - WEAVING_LAZY_TEST_VALUE); - this.verifySetProperty(Customization.WEAVING_LAZY_PROPERTY, - WEAVING_LAZY_KEY, - WEAVING_LAZY_TEST_VALUE, - WEAVING_LAZY_TEST_VALUE_2); - } - - public void testAddRemoveWeavingLazy() throws Exception { - this.verifyAddRemoveProperty( - Customization.WEAVING_LAZY_PROPERTY, - WEAVING_LAZY_KEY, - WEAVING_LAZY_TEST_VALUE, - WEAVING_LAZY_TEST_VALUE_2); - } - - // ********** WeavingChangeTracking tests ********** - public void testSetWeavingChangeTracking() throws Exception { - this.verifyModelInitialized( - this.customization.getWeavingChangeTracking(), - WEAVING_CHANGE_TRACKING_KEY, - WEAVING_CHANGE_TRACKING_TEST_VALUE); - this.verifySetProperty(Customization.WEAVING_CHANGE_TRACKING_PROPERTY, - WEAVING_CHANGE_TRACKING_KEY, - WEAVING_CHANGE_TRACKING_TEST_VALUE, - WEAVING_CHANGE_TRACKING_TEST_VALUE_2); - } - - public void testAddRemoveWeavingChangeTracking() throws Exception { - this.verifyAddRemoveProperty( - Customization.WEAVING_CHANGE_TRACKING_PROPERTY, - WEAVING_CHANGE_TRACKING_KEY, - WEAVING_CHANGE_TRACKING_TEST_VALUE, - WEAVING_CHANGE_TRACKING_TEST_VALUE_2); - } - - // ********** WeavingFetchGroups tests ********** - public void testSetWeavingFetchGroups() throws Exception { - this.verifyModelInitialized( - this.customization.getWeavingFetchGroups(), - WEAVING_FETCH_GROUPS_KEY, - WEAVING_FETCH_GROUPS_TEST_VALUE); - this.verifySetProperty(Customization.WEAVING_FETCH_GROUPS_PROPERTY, - WEAVING_FETCH_GROUPS_KEY, - WEAVING_FETCH_GROUPS_TEST_VALUE, - WEAVING_FETCH_GROUPS_TEST_VALUE_2); - } - - public void testAddRemoveWeavingFetchGroups() throws Exception { - this.verifyAddRemoveProperty( - Customization.WEAVING_FETCH_GROUPS_PROPERTY, - WEAVING_FETCH_GROUPS_KEY, - WEAVING_FETCH_GROUPS_TEST_VALUE, - WEAVING_FETCH_GROUPS_TEST_VALUE_2); - } - - // ********** SessionCustomizer tests ********** - public void testSetSessionCustomizer() throws Exception { - this.verifyModelInitialized( - this.customization.getSessionCustomizer(), - SESSION_CUSTOMIZER_KEY, - SESSION_CUSTOMIZER_TEST_VALUE); - this.verifySetProperty(Customization.SESSION_CUSTOMIZER_PROPERTY, - SESSION_CUSTOMIZER_KEY, - SESSION_CUSTOMIZER_TEST_VALUE, - SESSION_CUSTOMIZER_TEST_VALUE_2); - } - - public void testAddRemoveSessionCustomizer() throws Exception { - this.verifyAddRemoveProperty( - 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( - this.customization.getWeaving(), - WEAVING_KEY, - WEAVING_TEST_VALUE); - this.verifySetProperty( - Customization.WEAVING_PROPERTY, - WEAVING_KEY, - WEAVING_TEST_VALUE, - WEAVING_TEST_VALUE_2); - } - - public void testAddRemoveWeaving() throws Exception { - this.verifyAddRemoveProperty( - Customization.WEAVING_PROPERTY, - 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( - this.customization.getDescriptorCustomizer(ENTITY_TEST), - 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 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); - } - - // ********** setting properties ********** - @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.setSessionCustomizer((String) newValue); - else if (propertyName.equals(Customization.WEAVING_PROPERTY)) - this.customization.setWeaving((Weaving) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected void verifyPutProperty(String propertyName, Object expectedValue) throws NoSuchFieldException { - if (propertyName.equals(Customization.THROW_EXCEPTIONS_PROPERTY)) - this.verifyPutProperty(propertyName, this.customization.getThrowExceptions(), expectedValue); - else if (propertyName.equals(Customization.WEAVING_PROPERTY)) - this.verifyPutProperty(propertyName, this.customization.getWeaving(), expectedValue); - else if (propertyName.equals(Customization.WEAVING_LAZY_PROPERTY)) - this.verifyPutProperty(propertyName, this.customization.getWeavingLazy(), expectedValue); - else if (propertyName.equals(Customization.WEAVING_CHANGE_TRACKING_PROPERTY)) - this.verifyPutProperty(propertyName, this.customization.getWeavingChangeTracking(), expectedValue); - else if (propertyName.equals(Customization.WEAVING_FETCH_GROUPS_PROPERTY)) - this.verifyPutProperty(propertyName, this.customization.getWeavingFetchGroups(), expectedValue); - else if (propertyName.equals(Customization.SESSION_CUSTOMIZER_PROPERTY)) - this.verifyPutProperty(propertyName, this.customization.getSessionCustomizer(), expectedValue); - else - this.throwMissingDefinition("verifyPutProperty", propertyName); - } - - 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 9122910d29..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/customization/CustomizationValueModelTests.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.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); - } - - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - 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 dd19708873..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/LoggingAdapterTests.java +++ /dev/null @@ -1,341 +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.event.PropertyChangeEvent; -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 ********** - - private PropertyChangeListener buildPropertyChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - LoggingAdapterTests.this.propertyChangedEvent = event; - LoggingAdapterTests.this.propertyChangedEventCount++; - } - - @Override - public String toString() { - return "Logging listener"; - } - }; - } - - // ********** 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); - 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( - this.logging.getLevel(), - LEVEL_KEY, - LEVEL_TEST_VALUE); - this.verifySetProperty(Logging.LEVEL_PROPERTY, - LEVEL_KEY, - LEVEL_TEST_VALUE, - LEVEL_TEST_VALUE_2); - } - - public void testAddRemoveLevel() throws Exception { - this.verifyAddRemoveProperty( - Logging.LEVEL_PROPERTY, - LEVEL_KEY, - LEVEL_TEST_VALUE, - LEVEL_TEST_VALUE_2); - } - - // ********** Timestamp tests ********** - public void testSetThrowExceptions() throws Exception { - this.verifyModelInitialized( - this.logging.getTimestamp(), - TIMESTAMP_KEY, - TIMESTAMP_TEST_VALUE); - this.verifySetProperty(Logging.TIMESTAMP_PROPERTY, - TIMESTAMP_KEY, - TIMESTAMP_TEST_VALUE, - TIMESTAMP_TEST_VALUE_2); - } - - public void testAddRemoveThrowExceptions() throws Exception { - this.verifyAddRemoveProperty( - Logging.TIMESTAMP_PROPERTY, - TIMESTAMP_KEY, - TIMESTAMP_TEST_VALUE, - TIMESTAMP_TEST_VALUE_2); - } - - // ********** Thread tests ********** - public void testSetThread() throws Exception { - this.verifyModelInitialized( - this.logging.getThread(), - THREAD_KEY, - THREAD_TEST_VALUE); - this.verifySetProperty(Logging.THREAD_PROPERTY, - THREAD_KEY, - THREAD_TEST_VALUE, - THREAD_TEST_VALUE_2); - } - - public void testAddRemoveThread() throws Exception { - this.verifyAddRemoveProperty( - Logging.THREAD_PROPERTY, - THREAD_KEY, - THREAD_TEST_VALUE, - THREAD_TEST_VALUE_2); - } - - // ********** Session tests ********** - public void testSetSession() throws Exception { - this.verifyModelInitialized( - this.logging.getSession(), - SESSION_KEY, - SESSION_TEST_VALUE); - this.verifySetProperty(Logging.SESSION_PROPERTY, - SESSION_KEY, - SESSION_TEST_VALUE, - SESSION_TEST_VALUE_2); - } - - public void testAddRemoveSession() throws Exception { - this.verifyAddRemoveProperty( - Logging.SESSION_PROPERTY, - SESSION_KEY, - SESSION_TEST_VALUE, - SESSION_TEST_VALUE_2); - } - - // ********** Exceptions tests ********** - public void testSetExceptions() throws Exception { - this.verifyModelInitialized( - this.logging.getExceptions(), - EXCEPTIONS_KEY, - EXCEPTIONS_TEST_VALUE); - this.verifySetProperty(Logging.EXCEPTIONS_PROPERTY, - EXCEPTIONS_KEY, - EXCEPTIONS_TEST_VALUE, - EXCEPTIONS_TEST_VALUE_2); - } - - public void testAddRemoveExceptions() throws Exception { - this.verifyAddRemoveProperty( - Logging.EXCEPTIONS_PROPERTY, - EXCEPTIONS_KEY, - EXCEPTIONS_TEST_VALUE, - EXCEPTIONS_TEST_VALUE_2); - } - - // ********** LogFileLocation ********** - public void testSetLogFileLocation() throws Exception { - this.verifyModelInitialized( - this.logging.getLogFileLocation(), - LOG_FILE_LOCATION_KEY, - LOG_FILE_LOCATION_TEST_VALUE); - this.verifySetProperty( - Logging.LOG_FILE_LOCATION_PROPERTY, - LOG_FILE_LOCATION_KEY, - LOG_FILE_LOCATION_TEST_VALUE, - LOG_FILE_LOCATION_TEST_VALUE_2); - } - - public void testAddRemoveLogFileLocation() throws Exception { - this.verifyAddRemoveProperty( - Logging.LOG_FILE_LOCATION_PROPERTY, - LOG_FILE_LOCATION_KEY, - LOG_FILE_LOCATION_TEST_VALUE, - LOG_FILE_LOCATION_TEST_VALUE_2); - } - - // ********** Logger tests ********** - public void testSetLogger() throws Exception { - this.verifyModelInitialized( - this.logging.getLogger(), - LOGGER_KEY, - this.getEclipseLinkStringValueOf(LOGGER_TEST_VALUE)); // model is storing EclipseLinkStringValue - this.verifySetProperty(Logging.LOGGER_PROPERTY, - LOGGER_KEY, - LOGGER_TEST_VALUE, - LOGGER_TEST_VALUE_2); - } - - public void testAddRemoveLogger() throws Exception { - this.verifyAddRemoveProperty( - Logging.LOGGER_PROPERTY, - LOGGER_KEY, - LOGGER_TEST_VALUE, - LOGGER_TEST_VALUE_2); - } - - // ********** setting properties ********** - @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)) - this.logging.setLogger((Logger) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected void verifyPutProperty(String propertyName, Object expectedValue) throws NoSuchFieldException { - if (propertyName.equals(Logging.LEVEL_PROPERTY)) - this.verifyPutProperty(propertyName, this.logging.getLevel(), expectedValue); - else if (propertyName.equals(Logging.TIMESTAMP_PROPERTY)) - this.verifyPutProperty(propertyName, this.logging.getTimestamp(), expectedValue); - else if (propertyName.equals(Logging.THREAD_PROPERTY)) - this.verifyPutProperty(propertyName, this.logging.getThread(), expectedValue); - else if (propertyName.equals(Logging.SESSION_PROPERTY)) - this.verifyPutProperty(propertyName, this.logging.getSession(), expectedValue); - else if (propertyName.equals(Logging.EXCEPTIONS_PROPERTY)) - this.verifyPutProperty(propertyName, this.logging.getExceptions(), expectedValue); - else if (propertyName.equals(Logging.LOG_FILE_LOCATION_PROPERTY)) - this.verifyPutProperty(propertyName, this.logging.getLogFileLocation(), expectedValue); - else if (propertyName.equals(Logging.LOGGER_PROPERTY)) { - if(expectedValue == null) { - this.verifyPutProperty(propertyName, this.logging.getLogger(), null); - } - else if(expectedValue.getClass().isEnum()) { - this.verifyPutProperty( - propertyName, - this.logging.getLogger(), - this.getEclipseLinkStringValueOf(LOGGER_TEST_VALUE)); // model is storing EclipseLinkStringValue - } - else - this.verifyPutProperty(propertyName, this.logging.getLogger(), expectedValue); - } - else - this.throwMissingDefinition("verifyPutProperty", propertyName); - } - - 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 d9c42f7095..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/logging/LoggingValueModelTests.java +++ /dev/null @@ -1,156 +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); - } - - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - throw new UnsupportedOperationException(); - } -} 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 e8d0bf6679..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,280 +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.event.PropertyChangeEvent; -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(); - } - - private PropertyChangeListener buildPropertyChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - SchemaGenerationAdapterTests.this.propertyChangedEvent = event; - SchemaGenerationAdapterTests.this.propertyChangedEventCount++; - } - - @Override - public String toString() { - return "SchemaGeneration listener"; - } - }; - } - - /** - * 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( - this.schemaGeneration.getCreateFileName(), - CREATE_FILE_NAME_KEY, - CREATE_FILE_NAME_TEST_VALUE); - this.verifySetProperty( - SchemaGeneration.CREATE_FILE_NAME_PROPERTY, - CREATE_FILE_NAME_KEY, - CREATE_FILE_NAME_TEST_VALUE, - CREATE_FILE_NAME_TEST_VALUE_2); - } - - public void testAddRemoveCreateFileName() throws Exception { - this.verifyAddRemoveProperty( - SchemaGeneration.CREATE_FILE_NAME_PROPERTY, - 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( - this.schemaGeneration.getDropFileName(), - DROP_FILE_NAME_KEY, - DROP_FILE_NAME_TEST_VALUE); - this.verifySetProperty( - SchemaGeneration.DROP_FILE_NAME_PROPERTY, - DROP_FILE_NAME_KEY, - DROP_FILE_NAME_TEST_VALUE, - DROP_FILE_NAME_TEST_VALUE_2); - } - - public void testAddRemoveDropFileName() throws Exception { - this.verifyAddRemoveProperty(SchemaGeneration.DROP_FILE_NAME_PROPERTY, 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( - this.schemaGeneration.getApplicationLocation(), - APPLICATION_LOCATION_KEY, - APPLICATION_LOCATION_TEST_VALUE); - this.verifySetProperty( - SchemaGeneration.APPLICATION_LOCATION_PROPERTY, - APPLICATION_LOCATION_KEY, - APPLICATION_LOCATION_TEST_VALUE, - APPLICATION_LOCATION_TEST_VALUE_2); - } - - public void testAddRemoveApplicationLocation() throws Exception { - this.verifyAddRemoveProperty(SchemaGeneration.APPLICATION_LOCATION_PROPERTY, - 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( - this.schemaGeneration.getOutputMode(), - OUTPUT_MODE_KEY, - OUTPUT_MODE_TEST_VALUE); - this.verifySetProperty( - SchemaGeneration.OUTPUT_MODE_PROPERTY, - OUTPUT_MODE_KEY, - OUTPUT_MODE_TEST_VALUE, - OUTPUT_MODE_TEST_VALUE_2); - } - - public void testAddRemoveOutputMode() throws Exception { - this.verifyAddRemoveProperty(SchemaGeneration.OUTPUT_MODE_PROPERTY, 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( - this.schemaGeneration.getDdlGenerationType(), - DDL_GENERATION_TYPE_KEY, - DDL_GENERATION_TYPE_TEST_VALUE); - this.verifySetProperty( - SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, - DDL_GENERATION_TYPE_KEY, - DDL_GENERATION_TYPE_TEST_VALUE, - DDL_GENERATION_TYPE_TEST_VALUE_2); - } - - public void testAddRemoveDdlGenerationType() throws Exception { - this.verifyAddRemoveProperty(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, DDL_GENERATION_TYPE_KEY, DDL_GENERATION_TYPE_TEST_VALUE, DDL_GENERATION_TYPE_TEST_VALUE_2); - } - - // ****** convenience methods ******* - @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 void verifyPutProperty(String propertyName, Object expectedValue) throws NoSuchFieldException { - if (propertyName.equals(SchemaGeneration.OUTPUT_MODE_PROPERTY)) - this.verifyPutProperty(propertyName, this.schemaGeneration.getOutputMode(), expectedValue); - else if (propertyName.equals(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY)) - this.verifyPutProperty(propertyName, this.schemaGeneration.getDdlGenerationType(), expectedValue); - else if (propertyName.equals(SchemaGeneration.APPLICATION_LOCATION_PROPERTY)) - this.verifyPutProperty(propertyName, this.schemaGeneration.getApplicationLocation(), expectedValue); - else if (propertyName.equals(SchemaGeneration.CREATE_FILE_NAME_PROPERTY)) - this.verifyPutProperty(propertyName, this.schemaGeneration.getCreateFileName(), expectedValue); - else if (propertyName.equals(SchemaGeneration.DROP_FILE_NAME_PROPERTY)) - this.verifyPutProperty(propertyName, this.schemaGeneration.getDropFileName(), expectedValue); - else - this.throwMissingDefinition("verifyPutProperty", propertyName); - } - - 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 22e2c7f566..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,204 +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.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; - -/** - * 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(); - } - - private PropertyChangeListener buildPropertyChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - SchemaGenerationBasicAdapterTests.this.propertyChangedEvent = event; - SchemaGenerationBasicAdapterTests.this.propertyChangedEventCount++; - } - - @Override - public String toString() { - return "outputMode listener"; - } - }; - } - - /** - * 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.verifyPutProperty(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.verifyPutProperty(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode()); - - // Replace again - this.persistenceUnitPut(outputModeKey, OUTPUT_MODE_TEST_VALUE_2); - this.verifyPutProperty(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.verifyPutProperty(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(); - } - }; - } - - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - 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 ddd26f67bc..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,229 +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); - } - - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - throw new UnsupportedOperationException(); - } -} |